whereis - locate the binary, source, and manual page files for a command
Но у вас должна быть более веская причина использовать [116480]dd[116481], чем простую операцию копирования файлов, где лучше использовать [116482]scp[116483], [116484]rsync[116485] и т.п.[116118].
раствор на перле. Первая строка вывода отличается от вашей (отсутствует -
после &
в требуемом выводе?).
#!/usr/bin/perl
use warnings;
use strict;
my $first = 1;
my @line;
sub output {
print join('&', @line), "\n" unless $first;
}
my $previous = q();
while (<>) {
chomp;
if (s/.*: //) {
output();
print "$_:";
$previous = q();
@line = ();
} else {
my ($prefix, $suffix) = split /-/;
if ($prefix ne $previous) {
push @line, "$prefix-$suffix";
} else {
push @line, "-$suffix";
}
$previous = $prefix;
}
undef $first;
}
output(); # Don't forget to output the last line.
awk -F '-|: ' '
function printit( sep,key) {
sep = ""
for (key in data) {
printf "%s%s", sep, data[key]
sep = "&"
}
print ""
delete data
}
$1 == "MGW" {
if (key1) printit()
key1 = $2
printf "%s:", key1
next
}
!data[key1,$1] {
data[key1,$1] = $0
next
}
{data[key1,$1] = data[key1,$1] "&-" $2}
END {printit()}
' file
VMG110:836-19&-23
VMG120:3802-1&-2&-3&3456-1&-2
VMG119:3248-1&-2&3802-8&-9&-10&-11&-12&-13&3457-18&-19&-20