![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
ps -ef |grep telnet | tr ":" " " | awk ' { for ( i=1; i<=NF; i++ ) { print $i; }}'
|
|
#3
|
|||
|
|||
|
Code:
awk 'BEGIN{FS="[ :]+"}{for(i=1;i<=NF;i++)print $i}'
|
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
just change awk to nawk and it works fine....
|
|
#6
|
|||
|
|||
|
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 ? |
|
#7
|
|||
|
|||
|
from man nawk
FS Input field separator regular expression; a space character by default. you are correct. |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|