combining lines in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting combining lines in files
# 8  
Old 04-13-2008
Yes,
or:

Code:
awk 'END{print RS}(/^[03] /&&NR>1&&$0=RS$0)||1' ORS= file

# 9  
Old 04-13-2008
Thank you both for your quick replies, i have it working fine now Smilie
# 10  
Old 04-13-2008
Another one:

Code:
awk 'END{print RS}$0=NR>1&&/^[03] /?RS$0:$0' ORS= file

# 11  
Old 10-16-2008
Combine all lines into one

I'm working with a file that looks like this:

00800273
1009 0.01
1010 3.88
1011 3.56
1012 4.05
1009 0.05

and want to combine all of the lines into one, so it looks like this:

00800273 1009 0.01 1010 3.88 1011 3.56 1012 4.05 1009 0.05

I'd like to use a sed or awk command.

The input file will not always have the same number of lines, but it is always between 3 and 9 lines long.

Thanks in advance for your help
# 12  
Old 10-16-2008
Code:
tr -s '\n'  ' '  < inputfile > newfile

# 13  
Old 10-16-2008
Quote:
Originally Posted by metagirrl
I'm working with a file that looks like this:

00800273
1009 0.01
1010 3.88
1011 3.56
1012 4.05
1009 0.05

and want to combine all of the lines into one, so it looks like this:

00800273 1009 0.01 1010 3.88 1011 3.56 1012 4.05 1009 0.05

I'd like to use a sed or awk command.

The input file will not always have the same number of lines, but it is always between 3 and 9 lines long.

Thanks in advance for your help
In awk:
Code:
awk '1' ORS=" " file>newfile

# 14  
Old 10-16-2008
Or:
Code:
paste -sd\  infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Combining lines in one line

Hi below is the input file snippet. here i want that all the line which is coming after 1 shoud be in one line. so for exanple if after 1 there is two lines which is starting with 2 should be combine in one line. input file content 1,8091012,BATCH_1430903_01,21,T,2,808738,,,,21121:87:01,... (19 Replies)
Discussion started by: scriptor
19 Replies

2. Shell Programming and Scripting

Combining two lines into one, UNIX

Hi All, I have a file which has the following sample lines -- <Member name="Canada" Currency="CAD" -- <Member name="UK" Currency="GBP" -- <Member name="Switzerland" Currency="CHF" -- <Member name="Germany" Currency="EUR" -- (11 Replies)
Discussion started by: dev.devil.1983
11 Replies

3. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

4. Shell Programming and Scripting

Combining lines in to one line

Hi Friends, I have a file1.txt 1001 jkilo yrhfm 200056 jhdf rjhwjkrh 3+u8jk5h3 uru ehjk 1002 jkfhk hfjkd 2748395 fdjksfh hefjkh 3hdfk ejkh kjhjke In the above if you see the firt charcter of each line mentioned in red has a pattern . I need to create another file where , the... (6 Replies)
Discussion started by: i150371485
6 Replies

5. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

6. Shell Programming and Scripting

Combining lines between two specific lines

Hi, I have a requirement like following: I have input file like: Question: 1 ----Multiple choice--- What is your favourite colour? Options: a) red b) blue c) none of these Question: 2 ---Multiple choice----- In which month did you join your first job? Options: a) Jan b) Feb c)... (11 Replies)
Discussion started by: ppatra
11 Replies

7. UNIX for Dummies Questions & Answers

Combining lines of files to new file

Hi everybody. I have a number of files that i would like to combine. however not concatenating, but rather extract lines from the files. Example: File1 ------ File2 ------File3 ... line11 ---- line21 ---- line31 ... line12 ---- line22 ---- line32 ... line13 ... (3 Replies)
Discussion started by: kabbo
3 Replies

8. Shell Programming and Scripting

help combining lines in awk

I seem to have gotten myself in over my head on this one. I need help combining lines together. I have a text file containing 24,000 lines (exactly why I need awk) due to bad formatting it has separated the lines (ideally it should be 12,000 lines total). Example of file: ... (2 Replies)
Discussion started by: blueheed
2 Replies

9. Shell Programming and Scripting

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line? I have the following file that contains some blank lines and some lines I would like to append to the previous line... current file: checking dsk c19t2d6 checking dsk c19t2d7 ... (2 Replies)
Discussion started by: mr_manny
2 Replies

10. Shell Programming and Scripting

Combining multiple lines

I am fairly new to scripting. But I have been able to extract and format all of my information required into one file. My issue is that one character is on a separate line. I need to be able to add the character to the previous line. ex. abcdefghi 1 bcdefghij 3 cdefghijk 4 need to... (4 Replies)
Discussion started by: DUST
4 Replies
Login or Register to Ask a Question