The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 77
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-02-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Quote:
Originally Posted by rochitsharma
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
could you define 'not working', pls?
An example might be helpful.

P.S. The 'out-of-the-box' awk's can only define RS as single characters - no regex for RS.
Reply With Quote
  #3 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 77
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
Reply With Quote
  #4 (permalink)  
Old 03-02-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
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
or with any other awk without using an RS:
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.
Reply With Quote
  #5 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 77
please could you explain the working of both the codes.

Regards
Rochit
Reply With Quote
  #6 (permalink)  
Old 03-02-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Quote:
Originally Posted by rochitsharma
please could you explain the working of both the codes.

Regards
Rochit
see above.
Reply With Quote
  #7 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 77
thanks alot.

Code looks fine. i'll try it and come back to you tommorrow.
thanks for the explanation too.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0