|
|||||||
| 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
|
|||
|
|||
|
Write 2nd and 3rd fields to a 4th file name?
I have a flatfile A.txt Code:
date|products|notes|location 121117|a108|this is a test|florida 121118|b111|just test it|tampa How do i write an awk to create a file name as location.txt and have products:notes Code:
awk -F'|' '{ print $2 ":" $3 }' A.txt > $4.txtI am sure it cannot write to $4.txt; how do you do that? Thanks. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
awk -F'|' '{ close(o);o=$4 ".txt";print $2,$3 >> o}' OFS=: A.txt |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
awk -F'|' '{ fname=$4; print $2 ":" $3 > fname; close (fname)}' A.txtIf you have duplicate $4 field values this will not work. |
|
#4
|
|||
|
|||
|
Jim, How do i write output to /some/where/fname.txt?
vgersh99, how do i write it to folder /some/where/o.txt ? I write to local. If i add path i got syntax erro. Thanks |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Code:
# change this: fname=$4; #to fname= "/path/to/some/where" $4; the space is the concatenation operator in awk. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks
|
| 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 extract 3rd,4th and 5th element | VicNetIT | Shell Programming and Scripting | 3 | 06-01-2012 04:40 AM |
| 1st column,2nd column on first line 3rd,4th on second line ect... | batcho | Shell Programming and Scripting | 6 | 04-06-2012 09:20 AM |
| search 3 file and write to 4th file (a bit complex) | gc_sw | Shell Programming and Scripting | 7 | 12-30-2010 03:42 AM |
| How to extract 3rd line 4th column of a file | krishnamurthig | Shell Programming and Scripting | 4 | 11-05-2008 04:15 AM |
| printing 3rd or 4th feild from last in awk. | djsal | Shell Programming and Scripting | 8 | 05-17-2004 10:46 AM |
|
|