The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 04:05 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 06:57 AM
How to pass one parameter from one column to another column in AWK prasanta jena Shell Programming and Scripting 1 07-30-2007 03:08 AM
replace a column values with the first value in column sumeet UNIX for Advanced & Expert Users 3 02-06-2007 10:13 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-05-2005 10:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-22-2005
ust ust is offline
Registered User
 

Join Date: Feb 2005
Posts: 95
separate out the column

I know "awk -F:" will separate out the column by ":" , now if I what to separate out the column by space also , what can I do ?


for example :

#ps -ef |grep telnet
root 10159 702 0 15:45 ? 00:00:00 in.telnetd: 192.168.0.1

how to separate out the column so that the column as below,

column 1 --> root
column 2 --> 10159
column 3 --> 702
column 4 --> 0
column 5 --> 15
column 6 --> 45
column 7 --> ?
column 8 --> 00
column 9 --> 00
column 10 --> 00
column 11 --> in.telnetd
column 12 --> 192.168.0.1

|awk {print $12} then output the result is 192.168.0.1 , in short , I want to separate the column , to let the column is separate by : and space at the same time like my above example , is it possible ? thx
Reply With Quote
Forum Sponsor
  #2  
Old 12-22-2005
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
ps -ef |grep telnet | tr ":" " " | awk ' { for ( i=1; i<=NF; i++ ) { print $i; }}'
Reply With Quote
  #3  
Old 12-22-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Code:
awk 'BEGIN{FS="[ :]+"}{for(i=1;i<=NF;i++)print $i}'
Reply With Quote
  #4  
Old 12-28-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Hi ...

I tried this out in one of my files having the data as below

20051202 07:02:03 07:38:23
20051203 07:01:35 07:33:44
20051204 07:01:39 07:37:41
20051205 07:01:47 07:39:39
20051206 07:01:57 07:40:53
20051207 07:01:49 07:45:16

But it still gives result as below .... it was not taking FS as either space or colon ...

$ awk 'BEGIN{FS="[ :]+"}{print $1}' filename
20051202 07:02:03 07:38:23
20051203 07:01:35 07:33:44
20051204 07:01:39 07:37:41
20051205 07:01:47 07:39:39
20051206 07:01:57 07:40:53
Reply With Quote
  #5  
Old 12-29-2005
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
just change awk to nawk and it works fine....
Reply With Quote
  #6  
Old 12-29-2005
Registered User
 

Join Date: Jul 2005
Location: Chennai
Posts: 39
Great .... that worked fine ... thanks a lot ....

i think nawk has the capability of taking regular expressions as field seperator which awk does not have .... am i right ?
Reply With Quote
  #7  
Old 12-29-2005
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
from man nawk

FS Input field separator regular expression; a space
character by default.

you are correct.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0