How to add record separator after certain lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add record separator after certain lines
# 1  
Old 03-05-2009
How to add record separator after certain lines

How to add record separator after certain lines?

I am faicing issue where some lines have result as successive line & some are not having. how can I add record separator after every record
here is example of data I have (line numbers are not present in data):
1. <enabled="true" name="dSuite1" dSuitei.x">
2. <name="simu" value="none"/>
3. <enabled="true" name="schekry1" schekry1y.x">
4. <enabled="true" name="schekry2" schekry2y.x">
5. <enabled="true" name="sptad1" sptad.x">
6. <name="simu" value="on"/>
7. <enabled="true" name="schekry3" schekry3y.x">

1st line has result as 2nd line but 3rd & 4th line are single

I want it like:

<enabled="true" name="dSuite1" beaVodSuiteCli.x">
<name="simu" value="none"/>
------------------
<enabled="true" name="schekry1" schekry1y.x">
------------------
<enabled="true" name="schekry2" schekry2y.x">
------------------
<enabled="true" name="sptad1" sptad.x">
<name="simu" value="on"/>
------------------
<enabled="true" name="schekry3" schekry3y.x">
# 2  
Old 03-05-2009
Code:
awk 'NR==1{print;next}/<enabled/{print "-------"}1' file

Regards
# 3  
Old 03-05-2009
I tried
awk 'NR==1 { print$0 ; next }/<enabled/{ print "-------" }'

but it just prints like(couple of time):
-------
-------
-------

No record is diaplayed at all in between the lines.
# 4  
Old 03-05-2009
Quote:
Originally Posted by sach253
I tried
awk 'NR==1 { print$0 ; next }/<enabled/{ print "-------" }'

but it just prints like(couple of time):
-------
-------
-------

No record is diaplayed at all in between the lines.
Compare your code with what I've post.

Regards
# 5  
Old 03-05-2009
Your code
awk 'NR==1{print;next}/<enabled/{print "-------"}1'

I tried this too but same thing. only 1st record is printed then ------- (btw 1 at end is unexpected)

Eg.
>less abc.txt | awk 'NR==1{print;next}/<enabled/{print "-------"}'
>Record1
-------
-------
-------

Please have a look
# 6  
Old 03-05-2009
Quote:
Originally Posted by sach253
(btw 1 at end is unexpected)
Wrong, the 1 means "print the current record".

This is what I get:

Code:
$ cat file
<enabled="true" name="dSuite1" dSuitei.x">
<name="simu" value="none"/>
<enabled="true" name="schekry1" schekry1y.x">
<enabled="true" name="schekry2" schekry2y.x">
<enabled="true" name="sptad1" sptad.x">
<name="simu" value="on"/>
<enabled="true" name="schekry3" schekry3y.x">
$
$
$ awk 'NR==1{print;next}/<enabled/{print "-------"}1' file
<enabled="true" name="dSuite1" dSuitei.x">
<name="simu" value="none"/>
-------
<enabled="true" name="schekry1" schekry1y.x">
-------
<enabled="true" name="schekry2" schekry2y.x">
-------
<enabled="true" name="sptad1" sptad.x">
<name="simu" value="on"/>
-------
<enabled="true" name="schekry3" schekry3y.x">
$
$

Regards
# 7  
Old 03-05-2009
Thanks, it worked for me with 'nawk'. I wa strying just 'awk'

Thanks a lot ..!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk regular expression for RS record separator

Hi, I'm using gawk to read a text file and count the sentences. I want to use a record separator of a period, exclamation mark and a question mark. The problem is that the file contains words like "Mr. Smith" so the periods in the appellation are tripping my record separator. This is my... (12 Replies)
Discussion started by: 1Brajesh
12 Replies

2. Shell Programming and Scripting

Use string as Record separator in awk

Hello to all, Please some help on this. I have the file in format as below. How can I set the record separator as the string below in red "No. Time Source Destination Protocol Length Info" I've tried code below but it doesn't seem to... (6 Replies)
Discussion started by: cgkmal
6 Replies

3. Shell Programming and Scripting

awk - single quotes as record separator

How do I use single quotes as record separator in awk? I just couldn't figure that out. I know how to use single quotes as field separator, and double quotes as both field and record separator ... (1 Reply)
Discussion started by: locoroco
1 Replies

4. Shell Programming and Scripting

apply record separator to multiple files within a directory using awk

Hi, I have a bunch of records within a directory where each one has this form: (example file1) 1 2 50 90 80 90 43512 98 0909 79869 -9 7878 33222 8787 9090 89898 7878 8989 7878 6767 89 89 78676 9898 000 7878 5656 5454 5454 and i want for all of these files to be... (3 Replies)
Discussion started by: amarn
3 Replies

5. Shell Programming and Scripting

awk, string as record separator, transposing rows into columns

I'm working on a different stage of a project that someone helped me address elsewhere in these threads. The .docs I'm cycling through look roughly like this: 1 of 26 DOCUMENTS Copyright 2010 The Age Company Limited All Rights Reserved The Age (Melbourne, Australia) November 27, 2010... (9 Replies)
Discussion started by: spindoctor
9 Replies

6. Shell Programming and Scripting

Using > as record separator

I have tried to use ">" as record separator, but it doesn't work. I have tried this: awk BEGIN{RS=">"}'{print $0}' input output: awk: BEGIN{RS=>}{print $0} awk: ^ syntax error awk BEGIN{RS="\>"}'{print $0}' input awk: BEGIN{RS=\>}{print $0} awk: ^ backslash not... (2 Replies)
Discussion started by: locoroco
2 Replies

7. Shell Programming and Scripting

awk - double quotes as record separator

How do I use double quotes as a record seperator in awk? (4 Replies)
Discussion started by: locoroco
4 Replies

8. Shell Programming and Scripting

need to create lines from ones that begin with the field separator

Hello, I need to modify an awk script to recognize the last field $NF when the line is split over more than 1 line. In my input file the field separator is the exclamation mark ! so FS="!" So here is my input file infile.txt, it has 2 records, the field separator is in bold: INPUT ... (6 Replies)
Discussion started by: script_op2a
6 Replies

9. Shell Programming and Scripting

awk & cut record separator problem

Hi All, I've got some strange behaviour going on when trying to manipulate a file that contains spaces. My input file looks something like this: xxxxxxxxx,yyyy,sss sss sss,bbbbbbb If I use awk: When running from the command line I get: sss sss sss But when running from a... (7 Replies)
Discussion started by: pondlife
7 Replies

10. Shell Programming and Scripting

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 (7 Replies)
Discussion started by: rochitsharma
7 Replies
Login or Register to Ask a Question