1753342 Members
5040 Online
108792 Solutions
New Discussion юеВ

awk command

 
SOLVED
Go to solution
Raju_S
Frequent Advisor

awk command

Hello,

When i issue the command shown below it works fine in HP-UX.

cat /etc/passwd |awk -F ":" '{print $1"|"$3"|"$4"|"$5"|"$6"|"$7}' >a.txt

But when i try the same command in Solaris it gives the following error...

awk: syntax error near line 1
awk: bailing out near line 1

Please resolve this issue.

Thanks & Regard
6 REPLIES 6
Steven Schweda
Honored Contributor

Re: awk command

rsh solaris_host 'cat /etc/passwd' | awk [...]

If you expect "awk" to work the same on
different systems, you would be wise to use
the same "awk" program on those systems. I
hear that GNU "awk" ("gawk") is fairly
portable.

http://www.gnu.org/software/gawk/gawk.html

If you want advice on "awk" on Solaris, you
might also try a Solaris forum.

http://www.sun.com/bigadmin/home/index.html
Dennis Handly
Acclaimed Contributor

Re: awk command

I would suspect it's because you don't have spaces around your strings and $ variables??
Raju_S
Frequent Advisor

Re: awk command

Hi Dennis,

It is still not working with spaces.

Regards
Robert-Jan Goossens_1
Honored Contributor
Solution

Re: awk command

Hi,

Try this,

# cat /etc/passwd |nawk -F ":" '{print $1"|"$3"|"$4"|"$5"|"$6"|"$7}' >a.txt

Regards,
Robert-Jan
Raju_S
Frequent Advisor

Re: awk command

Hello,

Thankyou Roberts. It worked.

Thank you all.

Regards
Raju_S
Frequent Advisor

Re: awk command

Hello,

It worked when used with nawk.

Regards