how do i join two lines from a input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do i join two lines from a input file
# 1  
Old 02-02-2011
how do i join two lines from a input file

HI all,
i have a input file,i have to join 2nd line into firstline and 4th line into 2nd line and so on..
for this we also consider odd no. of line.It's operate on original input file but output file should temp file.
like ..
filename=cdr.cfg
Code:
line1
line2
line3
line4

Desired output should be like this...
filename=temp.cfg
Code:
line1line2
line3line4

If odd no. of lines are in file,then output should be like this..
Code:
line1line2
line3

Thnaks
surya

Last edited by Scott; 02-02-2011 at 06:59 AM.. Reason: Code tags
# 2  
Old 02-02-2011
Hi,

Try this:
Code:
$ perl -pE 's/\n// if ($. % 2);' infile

Regards,
Birei
# 3  
Old 02-02-2011
Try this,
Code:
paste  -d '' - -  < inputfile


Last edited by pravin27; 02-02-2011 at 07:54 AM..
# 4  
Old 02-02-2011
Request you to use code tags icon to wrap your input/output files for better readability.
Code:
awk '{r=$0;print v=getline? r $0:r}' inputfile > outfile

# 5  
Old 02-02-2011
use the paste command
as paste 1st filename 2nd filename
# 6  
Old 02-02-2011
Code:
$ ruby -ne 'print ($.% 2==0)?$_ : $_.chomp!' file 
line1line2 
line3line4

# 7  
Old 02-02-2011
Code:
sed 'N;s/\n//'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to join separate lines in a single one from xml file

Hi all, I need help to parse this xml file that has paragraphs broken in different lines and I would like to join in a single line. I hope you can understand my explanation. Thanks for any help/direction. The script could be in bash, awk, ruby, perl whatever please In the output I want:... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

2. Shell Programming and Scripting

Join Lines every paragraph in a file.txt

Hi all, Is there any idea on how to automate convert the paragraph in one line in a file, this will happen after OCR the documents, OCR split every paragraph. I need to join all the paragraph in one line. #cat file.txtThe Commission on Higher Education (CHED) was created through Republic Act... (7 Replies)
Discussion started by: lxdorney
7 Replies

3. Shell Programming and Scripting

Join multiple lines from text file

Hi Guys, Could you please advise how to join multiple details lines into single row, with HEADER 1 as the record separator and comma(,) as the field separator. Input: HEADER 1, HEADER 2, HEADER 3, 11,22,33, COLUMN1,COLUMN2,COLUMN3, AA1, BB1, CC1, END: ABC HEADER 1, HEADER 2,... (3 Replies)
Discussion started by: budz26
3 Replies

4. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

5. UNIX for Dummies Questions & Answers

Join lines in a file????

Hello UNIX gurus, I am new to the world of UNIX. Hopefully I am submitting my question at the right forum. Here is my dilemma - I have a file with contents like this - "line1","Hello","World","Today is a wonderful day","yes it is" "line2","Hello","World","Today is a beautiful day","oh... (8 Replies)
Discussion started by: foolishbar
8 Replies

6. Shell Programming and Scripting

Help in unix script to join similar lines of input

Hi, I have been thinking of how to script this but i have no clue at all.. Could someone please help me out or give me some idea on this? I would like to group those lines with the same first variable in each line, joining the 2nd variables with commas. Let's say i have the following input. ... (3 Replies)
Discussion started by: rei125
3 Replies

7. Shell Programming and Scripting

join lines in file

I have a file like this: --------------------------------------------------------------- 26 00:04:48,440 --> 00:04:51,440 I don't know why he can't just do the Great Apache Flaming Arrow Act. 27 00:04:52,440 --> 00:04:54,839 Didn't you tell him to use the gopher snake? 28... (1 Reply)
Discussion started by: thailand
1 Replies

8. Shell Programming and Scripting

join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like: 1 200.3 -0.3 2 201.7 -0.32 ... 87 200.2 -0.314 I have another file which contains data that was taken at certain of these 87 positions. i.e.: 37 125 42 175 86 142 where the first... (1 Reply)
Discussion started by: jackiev
1 Replies

9. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

10. Shell Programming and Scripting

join on a file with multiple lines, fields

I've looked at the join command which is able to perform what I need on two rows with a common field, however if I have more than two rows I need to join all of them. Thus I have one file with multiple rows to be joined on an index number: 1 randomtext1 2 rtext2 2 rtext3 3 rtext4 3 rtext5... (5 Replies)
Discussion started by: crimper
5 Replies
Login or Register to Ask a Question