|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
redirect to a file based on a value in a field
Hi all! Is it possible with awk to redirect all the records of a file that match a string in a field to a specific file. input.tab: Code:
aaaaa|bbbbbb|KKKKK cccccc|dddddd|SSSSS eeeeee|ffffffff|SSSSS ggggg|hhhhhh|KKKKK redirected to 2 separate files depending on the value in $3: output_1.tab (only lines with "KKKKK" in $3): Code:
aaaaa|bbbbbb|KKKKK ggggg|hhhhhh|KKKKK output_2.tab (only lines with "SSSSS" in $3): Code:
cccccc|dddddd|SSSSS eeeeee|ffffffff|SSSSS If someone could give me a clue, it would be great ! Thx ! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
You can put the right filename in a string, depending on the value of $3. Then you can use: Code:
print > string To print to that file... |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Ok, I was wondering if there was a built-in variable like FILENAME but for the other way
Thanks anyway ! |
|
#4
|
||||
|
||||
|
FILENAME is a built-in variable but it would not be useful here, as it contains the name of the current input file, in this case "input.tab" ..
|
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
lucasvs (06-26-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to split the data based on field from csv file? | somehanu | Shell Programming and Scripting | 8 | 03-31-2011 04:50 AM |
| Update a field in a file based on condition | kichu | Shell Programming and Scripting | 1 | 12-07-2010 12:57 PM |
| Spliting file based field pattern | raghavendra.cse | Shell Programming and Scripting | 3 | 06-30-2010 10:56 AM |
| Split file based on field | s_adu | Shell Programming and Scripting | 6 | 05-07-2009 02:08 PM |
| add lines automatically based on a field on another file | melanie_pfefer | Shell Programming and Scripting | 0 | 07-24-2008 02:59 AM |
|
|