Skip to main content
added 308 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many of the programs under /usr/bin and /bin on Solaris are not POSIX compatible.

Or you can use perl for portable:

$ perl -nle '                  
    unless (/,/) {                  
        push @a, $_;       
        next;
    }
    @l = split ",", $_;
    print "$a[$i++],$l[1]";
' file2.txt file1.txt
xyz,sachin
pressure,kumar

Even shorter:

$ perl -F',' -anle '
    if (@F == 1) {push @a,$_;next}    
    print "$a[$i++],$F[1]";
' file2.txt file1.txt

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many of the programs under /usr/bin and /bin on Solaris are not POSIX compatible.

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many of the programs under /usr/bin and /bin on Solaris are not POSIX compatible.

Or you can use perl for portable:

$ perl -nle '                  
    unless (/,/) {                  
        push @a, $_;       
        next;
    }
    @l = split ",", $_;
    print "$a[$i++],$l[1]";
' file2.txt file1.txt
xyz,sachin
pressure,kumar

Even shorter:

$ perl -F',' -anle '
    if (@F == 1) {push @a,$_;next}    
    print "$a[$i++],$F[1]";
' file2.txt file1.txt
added 9 characters in body
Source Link
slm
  • 379.7k
  • 127
  • 793
  • 897

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many programof the programs under /usr/bin and /bin inon Solaris isare not POSIX compatible.

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many program under /usr/bin and /bin in Solaris is not POSIX compatible.

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many of the programs under /usr/bin and /bin on Solaris are not POSIX compatible.

Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

You should try @devnull's answer with /usr/xpg4/bin/awk or nawk.

Many program under /usr/bin and /bin in Solaris is not POSIX compatible.