![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting fields of a line | Digby | UNIX for Dummies Questions & Answers | 6 | 03-12-2008 09:29 AM |
| displaying mutliple fields on command line | Trellot | UNIX for Dummies Questions & Answers | 3 | 11-02-2007 07:37 AM |
| Grep Line with Matching Fields | hemangjani | UNIX for Advanced & Expert Users | 13 | 08-10-2007 11:46 AM |
| how to include field separator if there are blank fields? | ReV | Shell Programming and Scripting | 19 | 07-13-2005 04:50 AM |
| AWK create loop for fields | tonet | Shell Programming and Scripting | 1 | 07-07-2005 09:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
need for loop to include fields as one line
another question that could possibly be answered with awk...
Code:
#cat filename ab cd ef:ghi:jk lm:nop qrs ab cd ef:ghi:jk lm:nop qrs ab cd ef:ghi:jk lm:nop qrs ab cd ef:ghi:jk lm:nop qrs # for x in `awk 'sub($1" +"$2" +","",$0) ' filename`; do echo $x; done ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs IE Code:
# for x in `awk 'sub($1" +"$2" +","",$0) ' filename`; do echo $x; done ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs Last edited by prkfriryce; 03-23-2007 at 11:01 AM.. |
|
||||
|
Quote:
just read and prints the line Code:
awk '{ print }' file
Sorry if I have not understood correctly! Could you please post the expected output ? ![]() |
|
||||
|
Expected/desired output:
# for x in `awk 'sub($1" +"$2" +","",$0) ' filename`; do echo $x; done ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs the 'for loop' separates each awk line into three variables, so instead of 4 lines, there are 12: actual output: # for x in `awk 'sub($1" +"$2" +","",$0) ' filename`; do echo $x; done ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs |
|
||||
|
Code:
awk -F " " '{ print $3, $4, $5 }' filename
Code:
awk -F " " '{ for ( i=3; i<=NF; i++ ) { printf "%s ", $i } printf "\n" }' filename
Last edited by matrixmadhan; 03-23-2007 at 11:19 AM.. |
|
||||
|
Quote:
ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs ef:ghi:jk lm:nop qrs Regardless of the awk output, the 'for loop' logic still interprets each awk oupt line as a three variables. I would liek to set each awk output line as a string to be able to parse in a later function |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|