![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 | Thread Starter | Forum | Replies | Last Post |
| mutliple files in the same directory | epi8 | Shell Programming and Scripting | 8 | 05-12-2008 11:04 PM |
| process mutliple files in the same directory | epi8 | UNIX for Dummies Questions & Answers | 1 | 05-12-2008 11:43 AM |
| How to split a field into two fields? | vbrown | Shell Programming and Scripting | 4 | 02-21-2008 03:50 AM |
| can Awk split my field on the . | oly_r | Shell Programming and Scripting | 6 | 10-26-2007 04:16 PM |
| Split a field in awk script | CamTu | Shell Programming and Scripting | 4 | 03-21-2005 01:03 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi Gurus,
I am new to UNIX(HP). my requirmnet is File needs to needs to be split into multiple files dependa on one key value. example 1 abc 333 us 2 bbc 444 ch 5 nnn 333 kk 7 hhh 555 ll 3 hhh 333 hh now the requirment is line with 333 should be copied into test1.txt and the rest to test2.txt. normally i will recieve 2 files name a1.txt and a2.txt once a daily to one of my server . Depends on the condition i need to split the files and send it to 2different servers. appreciate your help on the above. Thanks Arun |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk '{ if ($3 == "333") {print $0 > test1.txt}
else { print $0 > test2.txt}
} ' inputfile
|
|
#3
|
|||
|
|||
|
Or try
Code:
grep 333 inputfile >test1.txt grep -v 333 inputfile >test2.txt |
|
#4
|
|||
|
|||
|
Thanks Jim,
but when i appy the same code i am getting error like below. i don;t know why. awk ' { if ($3 == "RD018414292") {print $0 > test1.txt} else { print $0 > test2.txt} } ' arigmrec03_2007_02_02_15_06_59_505.success syntax error The source line is 1. The error context is { if ($3 == "RD018414292") {print $0 > >>> test1. <<< txt} else { print $0 > test2.txt} } awk: The statement cannot be correctly parsed. The source line is 1. is that $3 in if statment refers to 3rd column? but my actual file cotains may fileds; i have just copied one line below. 200804NA441200119000000000000000200804083727708DELPHI DELCO ELECTRONICS EFTRD002136823A8020570218671R08098 -00000000131541012900015979340420080327GM 56741 0000000000000NN DELPHI DELCO ELECTRONICS EFTOSYNDCN052777597 200804042304 SPON USD-000000001315410USD 000001000000000 20080502 in that above line i need to capture a field value(RD002136823) starting at the position 78 and ending at 89 into another file. also can i give multiple files as input to code? waiting for your response Arun |
|
#5
|
|||
|
|||
|
Try the grep above (we seem to have posted at exactly the same time). You can give multiple files as input to most Unix commands.
Code:
grep RD018414292 file1 file2 file3 >have grep -v RD018414292 file1 file2 file3 >have.not |
|
#6
|
|||
|
|||
|
Hi Era,
Thanks for the help. but requirment is little bit different. you have given example for a single value search, but i want to search multiple values in given files and put result into single file. waiting for your response. Thanks Arun |
|
#7
|
|||
|
|||
|
Different values in different files, or multiple values in multiple files, or different sets of values in different sets of files?
Code:
egrep 'first|second|third' file1 file2 file3 >have egrep -v 'first|second|third' file1 file2 file3 >have.not Code:
>have; >have.not # make sure they're empty before we start while read file value; do grep "$value" "$file" >>have grep -v "$value" "$file" >>have.not done <<HERE file1 first file2 second.*rege[xz]magic$ file3 how sweet I roam from field to field HERE |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|