Record terminator on alternate line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Record terminator on alternate line
# 1  
Old 08-22-2013
Record terminator on alternate line

Hello All,

I have csv file like this

Code:
1,"suzi","305
Barehills","Vancover",34256
2,"molly","456
beverleyhills","Minisotta",234876

I want to put a customized record terminator on every alternate lines of this file.
The file is a input to database and the record terminator is by default taken as \n.

After the transition the file should look like this

Code:
1,"suzi","305
Barehills","Vancover",34256;
2,"molly","456
beverleyhills","Minisotta",234876;

Please help me doing this.
# 2  
Old 08-22-2013
Code:
awk '!(NR%2){$(NF+1)=";"}1' filename

This User Gave Thanks to krishmaths For This Post:
# 3  
Old 08-22-2013
Code:
awk '!(NR%2){$NF=$NF";"}1' infile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 4  
Old 08-22-2013
Thanks.

Both the solutions works great.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reject the record if the record in the next line does not begin with 2.

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten 2eleven 2twelve 1thirteen 2fourteen The output should be: (5 Replies)
Discussion started by: supchand
5 Replies

2. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

3. Shell Programming and Scripting

Finding longest line in a Record

Good Morning/Afternoon All, I am using the nawk utility in korn shell to find the longest field and display that result. My Data is as follows: The cat ran The elephant ran Milly ran too We all ran I have tried nawk '{ if (length($1) > len) len=length($1); print $1}' filename The... (5 Replies)
Discussion started by: SEinT
5 Replies

4. Shell Programming and Scripting

Inserting a line in a file after every alternate line

Friends , I have a large file and i need to insert a line after every line.I am actually unaware how to do it.Any help appreciated. My File control station *ATM* , qread $OSS.Jul13A.FI01 interval 1 intcount 1 control station *ATM* , qread $OSS.Jul13A.FI02 interval 1 intcount... (4 Replies)
Discussion started by: appu2176
4 Replies

5. Shell Programming and Scripting

Get Nth record from last line

I have a growing file . I knew only last few lines which is constant for evey job run. I'd need to pull the Nth record from the last line. In this case i should not use search pattern. (2 Replies)
Discussion started by: ford2020
2 Replies

6. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

7. Shell Programming and Scripting

AWK - if last line/record do something

Hello: I am trying to perform a certain action if the current record is the last line of the input file. But I am unable to figure out how to determine the last line of a file in awk. I need to do something like this: awk '{ if (lastline == NR) Do Something}' myfile.txt I have tried the... (3 Replies)
Discussion started by: PacificWonder
3 Replies

8. Shell Programming and Scripting

Line Terminator

Hi Guys, This is Narasa i am new to this forum.I am very proud to join this forum. I have a question on Line termination for fixed length file. We got a file from mainframe having fixed length of 587 but when i extract the zip file with notepad it looks like continuous line with out any... (3 Replies)
Discussion started by: narasa
3 Replies

9. Shell Programming and Scripting

how to extract last line in record

Hi all!! After experiencing great helpfulness the last time I posted a problem at this site, I once again turn to the forum for expert help. The problem: I have a file.dat containing x, y, and z coordinates, like: x y z 1 1 4 1 2 3 1 3 9 2 1 7 2 2 2 2 3 8 3 1 ... (7 Replies)
Discussion started by: bjorb
7 Replies

10. UNIX for Dummies Questions & Answers

adding line terminator

Can someone help , how to add a terminator at the end of each line through shell command. ex: input file: abc xyz2 outputfile (terminator is !) abc! xyz2! (1 Reply)
Discussion started by: thanuman
1 Replies
Login or Register to Ask a Question