![]() |
|
|
|
|
|||||||
| 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 01: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 02:46 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#15
|
|||
|
|||
|
It reads number.dat once, examining each line in turn.
Can't help you with the "command garbled" error; it works for me here. Is it the addition of the field separator or the full path name which is causing it confusion? You seem to have a space between AAA and \| -- this will only match on a sequence where there really is a space between "AAA" and the vertical bar. |
| Forum Sponsor | ||
|
|
|
#16
|
||||
|
||||
|
Reg: split the data file based on the file header...
Hi Vinay,
Try with this script and it may solve your problem awk '$1=="AAA" print { $0 ;}' Number.dat > AAA.dat awk '$1=="BBB" print { $0 ;}' Number.dat > BBB.dat Let me know if you need more details Regards, Siva.P Bangalore |
|
#17
|
|||
|
|||
|
Syntax errors notwithstanding, that obviously reads the file multiple times. But yes, if you have trouble with sed, then awk is also an option.
Code:
awk -F '|' '$1 == "AAA" { print >"/path/to/AAA.dat"; next }
$1 == "BBB" { print > "/path/to/BBB.dat"; next }' numbers.dat
Like sed, awk reads the input file once only, so by putting the commands in a single script we manage to meet your requirement. |
|
#18
|
|||
|
|||
|
Hello Shiva,
Its giving an error : awk: syntax error near line 1 awk: bailing out near line 1 Also as you have said, awk '$1=="AAA" print { $0 ;}' Number.dat > AAA.dat awk '$1=="BBB" print { $0 ;}' Number.dat > BBB.dat If I am correct, need to give these scripts seperately. I have some concerns, I dont want to run thro' number.dat repeatedly. I am planning to make a script that allows to sort and move data to respective files without traversing thro' it again and again. Kindly assist if possible, Thanks and regards, Vinay |
|
#19
|
|||
|
|||
|
Scroll back up to comment #17 if you missed that.
|
|
#20
|
|||
|
|||
|
hi era, shiva,unix gurus,
I tried the awk present in comment #17. awk -F '|' '$1 == "AAA" { print >"/path/to/AAA.dat"; next } $1 == "BBB" { print > "/path/to/BBB.dat"; next }' numbers.dat Its giving an error. awk: syntax error near line 1 awk: bailing out near line 1 I am not able to figure out what the error is... You guys have made my day... Now I have started going thro' awd basics and sed basics. Truly great concepts... Please assist me if possible Thanks and Regards, Vinay |
|
#21
|
|||
|
|||
|
Perhaps at this point it would make sense to step back and tell us what platform you're on and whether you can figure out the versions of sed and awk you have at your disposal.
If you're on something like HP-UX or Irix and you have very old versions of both awk and sed, maybe a Perl script would be the best solution. If you're on HP-UX or Solaris then there may be more recent versions of these commands if you look around for a bit. Search these forums for xpg4 and the name of your platform for some pointers. Maybe you have a command nawk or mawk or gawk which would work better than just awk. Here's a Perl script, for the heck of it. Code:
perl -ne 'if (m/^(AAA|BBB)\|/) { open (H, ">>$1.dat"); print H; close H; }' numbers.dat
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions, solaris |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|