![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove duplicate records with out sort | svenkatareddy | Shell Programming and Scripting | 19 | 06-11-2008 03:10 PM |
| How to remove duplicate records with out sort | svenkatareddy | SUN Solaris | 2 | 02-28-2008 08:38 AM |
| How to Sort Records Uniquely? | earnstaf | UNIX for Dummies Questions & Answers | 12 | 02-19-2008 09:23 AM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 01:15 PM |
| dynamically split the records | braindrain | Shell Programming and Scripting | 6 | 11-04-2005 11:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Sort & Split records in a file
Hi,
I am new to scripting. I need a script to sort and the records in a file and then split them into different files. For example, the file is: H1...................... H2...................... D2.................... D2.................... H1........................ H2........................ Etc., Here the file should be sorted and splitted in such a way that all H1 records will be put into one file. all H2 in other file and so on. Pls help. Regards, Sunitha |
|
||||
|
Hi,
Thanks for the reply. I have written the script something like this. #!/usr/bin/ksh ############################################################################# #---------------------------------------------------------------------------- #Check for the input files. #---------------------------------------------------------------------------- cd /app/chdata/workflow/suppl/esoutput/spd/flatfile sort /app/chdata/workflow/suppl/esoutput/spd/flatfile/testfile | awk '{ file=substr($0,1,2); print >> /app/chdata/workflow/suppl/esoutput/spd/flatfile/testfile1_out.txt }' However when I tried executing it says cannot execute. Also, is my script right? If not pls correct me. Regards, Sunitha |
|
||||
|
Hi,
I tried executing the script. I got the error saying: syntax error The source line is 1. The error context is { file=substr($0,1,2)".txt"; print >> >>> /app/chdata/workflow/suppl/esoutput/spd/flatfile/testfile1_out. <<< txt } awk: The statement cannot be correctly parsed. The source line is 1. |
|
||||
|
You should leave it as 'file', not replace it with the filename. The variable called 'file' contains the filename it will output to, which is created by taking the first two characters of the input record, and as you have done, adding ".txt" to the end.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|