2

I am trying to write a script that would combine two files into one and should work in both Solaris 5.10 and a Linux box.

File1:

dit710
dit710
dit720
dit720

File2:

FacA D0000000000000001
FacA D0000000000000002
FacA D0000000000000030
FacB D00000000000000980

Desired Output:

dit710,FacA,D0000000000000001
dit710,FacA,D0000000000000002
dit720,FacA,D0000000000000030
dit720,FacB,D00000000000000980

What I tried?

paste File1 File2 |nawk '{$1=$1}1' OFS=","

(Above command works in Solaris but does not work in Linux)

paste File1 File2 |awk '{$1=$1}1' OFS=","

(Above command works in Linux but does not work in Solaris)

I am using Korn Shell. Can someone suggest another way which works in both Solaris and Linux?

Note that File2 may contain more than 3 columns but always have equal number of columns.

  • 1
    Try paste File1 File2 | tr '[[:blank:]]' , – don_crissti Apr 5 '16 at 19:56
  • @don_crissti Command you provided works only in Linux, its not working in Solaris. – ayrton_senna Apr 5 '16 at 20:43
  • replace [[:blank:]] with a literal tab followed by a space... – don_crissti Apr 5 '16 at 20:45
  • @don_crissti No luck, not working in solaris or linux – ayrton_senna Apr 5 '16 at 20:54
  • Solaris has an 'XPG4' option that makes many things including awk more like other/standard Unixen, see unix.stackexchange.com/questions/198905/… – dave_thompson_085 Apr 6 '16 at 3:14
2

I was able to resolve this issue myself, but I wouldn't call it a straight forward approach. Since awk works in Linux, but not nawk, I created a soft link in Linux host to redirect nawk to awk. Now I can use nawk in both Solaris and Linux without any issues.

ln -s /bin/awk /bin/nawk
  • Not sure what distro you are running but Debian based distributions at least, automatically create this link. – psusi Apr 6 '16 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.