Skip to main content
3 of 3
added 308 characters in body
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

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
cuonglm
  • 158.2k
  • 41
  • 342
  • 420