![]() |
|
|
|
|
|||||||
| 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 |
| Spliting file based on condition | Raamc | Shell Programming and Scripting | 2 | 05-15-2008 08:51 AM |
| How to split the String based on condition? | sankar reddy | Shell Programming and Scripting | 2 | 03-19-2008 03:48 AM |
| Moving file to directory based on condition. | ramanagh | Shell Programming and Scripting | 2 | 02-02-2008 07:41 AM |
| Read file based on condition | sbasetty | Shell Programming and Scripting | 5 | 01-31-2007 10:54 PM |
| Splitting a file based on some condition and naming them | srivsn | Shell Programming and Scripting | 1 | 12-07-2005 07:27 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
awk script to split a file based on the condition
I have the file with the records like
4234234 US phone 3244234 US cup 2342342 CA phone 8947234 US phone 2389472 CA cup 2348972 US maps 3894234 CA phone I want the records with (US,phone) as record to be in one file, (Us, cup) in another file and (CA,cup) to be in another I mean all records with the last two records forming unique pair in the one file itself Is it possible in awk? |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks vino, it worked
I have one more question If the file is like this WSRTK10000000000000067839904809787489959595924667889USMNC WSRTK10000893479900006783990480978748995959592466673CNATT WSRTK10000893472387462342349899000067839904809787455USAPT I know that the last 5 characters in each line is my search pattern and my problem remains the same I want lines containing patterns like USMNC to go to US_MNC etc Can I extract last few characters of each line in awk? |
|
||||
|
Here this works fine.
Code:
#! /bin/sh while read line do name=`echo $line | sed -n -e 's/\(.*\)\([A-Z][A-Z]\)\([A-Z][A-Z][A-Z]\)/\2_\3/p'` echo "$line" >> $name.txt done < list.txt Vino |
||||
| Google The UNIX and Linux Forums |