LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-17-2007, 06:01 AM   #1
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Rep: Reputation: 15
awk help


hi all,
this command is working fine in linux. it prints the total number of characters in each line of a file.

$gawk -F '' '{ print NF}' a.txt

But this is not working in solaris. Please suggest me a proper field separator for solaris awk/nawk.

Thanks and Regards,
uttam hoode
 
Old 12-17-2007, 06:31 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Why not...
Code:
awk '{print length}'
 
Old 12-17-2007, 06:36 AM   #3
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Original Poster
Rep: Reputation: 15
superb!!!! u rock
 
Old 12-17-2007, 08:32 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The gawk utility is not quite the same as Solaris' oawk ("old" awk) or nawk ("new" awk); you probably ought to be using nawk on Solaris (because /bin/awk is owak -- try a long list to see if /bin/awk is the same size as /bin/owak or /bin/nawk to be sure). oawk is the default for compatibility with existing AWK programs in the system utilities.

The man page for nawk shows the syntax for -F ERE, the input field separator, which is different than the -F FS argument on owak.

The differences between gawk and nawk can be subtle but they can also cause you headaches -- best to stick with nawk syntax for both and try to avoid the "extensions" found in gawk.

If you're interested, the source code for nawk (along with a large number of standard System V utilities (the ones Solaris uses) are available at http://heirloom.sourceforge.net, nawk itself can be gotten from http://heirloom.sourceforge.net/tools.html either as part of a set of utilities or by itself with CVS (instructions on the page). You can compile and install nawk on your Linux system and you'll be able to write AWK programs that will port between Linux and Solaris.

Sorry if this is a bit beyond the scope of your question, but as time goes on you may find the above useful developing on both Linux and Solaris. Hope this helps some.
 
Old 12-17-2007, 09:40 PM   #5
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Original Poster
Rep: Reputation: 15
Thanks a lot tronayne
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk help uttam_h Programming 9 10-16-2007 10:32 AM
awk help please stefaandk Programming 6 10-02-2007 07:50 AM
Awk opensource82 Linux - General 5 09-19-2007 09:08 AM
awk aggressivebloodcell Linux - Newbie 3 07-02-2007 11:51 PM
Help with awk kshkid Programming 1 12-22-2006 05:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration