![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 |
| how to read record by record from a file in unix | raoscb | UNIX for Dummies Questions & Answers | 1 | 05-16-2008 03:30 AM |
| awk & cut record separator problem | pondlife | Shell Programming and Scripting | 7 | 03-10-2008 01:05 AM |
| splitting a record and adding a record to a file | rsolap | Shell Programming and Scripting | 1 | 08-13-2007 10:58 AM |
| Help with unix separator | Black mage2021 | UNIX for Dummies Questions & Answers | 2 | 01-02-2006 07:49 PM |
| Separator in Makefile? | laila63 | Shell Programming and Scripting | 2 | 07-01-2004 07:11 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
record separator
can anyone tell me any way to change record separator (default is new line).
RS in nawk as not working. Thanks in advance. Regards Rochit |
| Forum Sponsor | ||
|
|
|
|||
|
my in put file is:
<CRM:MS=23746,............................; <EN:MS=23746..........................; ................................................; <CRM:5766,..............; <OP:.................................; my input file looks like this. in place of dots there are some more parameters. what i want is that the record separator new line (currently ) is replaced. i want the script to accept <CRM: as new field separatori.e my output file should look like: <CRM:MS=23746,............................;<EN:MS=23746..........................;.................. ..............................; <CRM:5766,..............;<OP:.................................; it will be very nice of you if you can help. Regards Rochit |
|
||||
|
use 'gawk' if you can:
Code:
# # set the RecordSeparator to '<CRM:' # # for the FIRST line - reevaluate the record equal to itself # for any OTHER line - reevaluate the record appending the RecordSeparator # to the beginning of the record. # # after the reevaluattion is done - PRINT the record. 'PRINT' is implicit as a # result of the record re-evaluation. # gawk -v RS='<CRM:' '$1=(FNR==1) ? $1 : RS $1' myFile Code:
# for the FIRST line/record - print it out (withOUT a new line) and o to the next line
FNR==1 { printf ;next }
#
# for any OTHER (other than the first) line/record:
# if the line/record starts with '<CRM:' - print the new line '\n' followed by
# a line itself.
# if the line/record does NOT start with '<CRM:' - print the line withOUT
# a new line '\n'
{printf (/^<CRM:/) ? "\n" $0 : $0}
# print new line '\n' after the LAST line processed
END { printf "\n" }
Last edited by vgersh99; 03-04-2006 at 08:26 AM. |