![]() |
|
|
|
|
|||||||
| 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 |
| Sorting your data with msort | iBot | UNIX and Linux RSS News | 0 | 05-19-2008 08:20 AM |
| sorting data using array in ksh | ali560045 | Shell Programming and Scripting | 4 | 12-04-2007 12:26 AM |
| Sorting blocks of data | alfredo123 | Shell Programming and Scripting | 8 | 07-05-2007 07:53 AM |
| Newbie Awk data sorting | i_am_a_robot | Shell Programming and Scripting | 5 | 05-04-2007 04:33 AM |
| Recovering lost folders/files data | Yorgy | UNIX for Dummies Questions & Answers | 0 | 03-15-2007 01:46 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello era / unix gurus,
I tried the following: sed -e "x;/^AAA/b" -e "/^BBB/b" -e d number.dat It works. But I need to divert it to different files .How do I do it. Kindly assist if possible Thanks and Regards, Vinay |
| Forum Sponsor | ||
|
|
|
|||
|
Did you try the script I posted above? If so, what's wrong with it? It writes lines matching "^AAA" to AAA.dat and lines matching the regular expression "^BBB" to BBB.dat, is that not what you want?
|
|
|||
|
Hello era,
The script u had sent did not work. Its giving an error sed: command garbled: /^AAA/wAAA.dat/^BBB/wBBB.dat That is why I tried sed -e "x;/^AAA/b" -e "/^BBB/b" -e d number.dat I am getting answer properly, but I dont know how to route it to different files. |
|
|||
|
Hi era,
sed -e '/^AAA/w AAA.dat' -e '/^BBB/w BBB.dat' number.dat works.. Thanks a lot. Can I specify the path where it should be stored: sed -e '/^AAA/w /export/home/vinay/AAA1.dat' -e '/^BBB/w /export/home/vinay/BBB1.dat' a.dat I hope there is some error Also does sed provides a way to search specific fields, like the -f1 (1st field) option Also does the sed -e '/^AAA/w AAA.dat' -e '/^BBB/w BBB.dat' number.dat traverses through the number.dat once or twice. .. Kindly assist me if possible Thanks and Regards, Vinay Last edited by Vinaykumar1; 05-14-2008 at 01:47 AM. |
|
|||
|
sed uses regular expressions only, you can create a regex to look at the first field only with regex constructs; the ^ is already halfway there, as it forces the match to happen at beginning of line. Suppose the field separator is a vertical bar; then you can just add that after the string you want to search for, to anchor it properly.
Code:
sed -e '/^AAA|/w/export/home/vinay/AAA1.dat' -e '/^BBB|/w/export/home/vinay/BBB1.dat' a.dat The vertical bar has special meaning to some regular expression engines, just like the ^ -- if you get erratic behavior (all lines matching all the time) then you need to backslash-quote it, like \|. It is unfortunate that there are different dialects of sed so that we can't know for sure whether or not this is an issue in your case. Last edited by era; 05-14-2008 at 01:52 AM. Reason: Separator is vertical bar, as per above |
|
|||
|
Hello era / unix gurus,
I tried the above script but its giving me sed: command garbled: /^AAA \|/w/export/home/cmohanku/vinay/AAA1.dat "Also does the sed -e '/^AAA/w AAA.dat' -e '/^BBB/w BBB.dat' number.dat traverses through the number.dat once or twice." Please help me if possible Thanks and Regards, Vinay |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions, solaris |
| Thread Tools | |
| Display Modes | |
|
|