LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2009, 04:58 AM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
awk output delimiters


I want to change the output of the script - add delimeters - whether they are spaces, commas, dashes, tab spaces. whatever

I tired awk -F"delimeter" but that did not work

sh-3.00$ for i in $( grep cancel: ~casper/data/resource | grep ncs100 | awk "{ print $4 }'
do
echo $i
done
220774
230335
457674
532584
sh-3.00$

what I am looking to do is get :220774, 230335, 457674, 532584 or
or 220774 230335 457674 532584

I want to pass this output to another shell script with the $@ argument variable.

I tired awk -IFS already.
 
Old 10-23-2009, 05:05 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Try setting the ORS (output record seperator).

To a space in the followinf example:
.....| grep ncs100 | awk "BEGIN { ORS = " "}{ print $4 }'

Hope this helps
 
Old 10-23-2009, 05:27 AM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
nice ORS - never heard of that one - just what I needs. arrrrgggggg!

casper@casper-laptop:~$ for i in $( ps auxwww | awk 'BEGIN { ORS= ","} { print $5 } ');
do
echo $i ;
done
3056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2528,0,0,0,0,1780,1780,1780,1780,1780,2308,0,2012 ,
1940,3508,2992,2888,2888,6432,6324,16388,3364,5204,3436,3448,2296,3488
 
Old 10-23-2009, 07:31 AM   #4
carters2
LQ Newbie
 
Registered: Sep 2009
Posts: 20

Rep: Reputation: 1
gawk '{FS = "[:,-]+"} {print $3","$5}'

This will delimit on colon, comma, and dash and print two values with a comma between them

Last edited by carters2; 10-23-2009 at 07:34 AM.
 
Old 10-23-2009, 08:17 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by carters2 View Post
gawk '{FS = "[:,-]+"} {print $3","$5}'

This will delimit on colon, comma, and dash and print two values with a comma between them
put your FS in BEGIN block
 
  


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/Sed do not produce any output MasterOfTheWind Linux - Newbie 6 05-24-2009 07:50 AM
Simple (?) awk, two delimiters int0x80 Programming 3 02-25-2009 08:53 AM
Awk Output kalyanofb Programming 4 02-02-2007 02:23 AM
Awk output Trouble fooforon Programming 6 04-12-2004 07:14 AM
Awk and Shell CMD Output xanthium Programming 16 04-24-2002 06:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:01 PM.

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