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.

5
  • 1
    Try paste File1 File2 | tr '[[:blank:]]' , Commented Apr 5, 2016 at 19:56
  • @don_crissti Command you provided works only in Linux, its not working in Solaris. Commented Apr 5, 2016 at 20:43
  • replace [[:blank:]] with a literal tab followed by a space... Commented Apr 5, 2016 at 20:45
  • @don_crissti No luck, not working in solaris or linux Commented Apr 5, 2016 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/… Commented Apr 6, 2016 at 3:14

1 Answer 1

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
1
  • Not sure what distro you are running but Debian based distributions at least, automatically create this link. Commented Apr 6, 2016 at 1:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.