help combining lines in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help combining lines in awk
# 1  
Old 03-23-2006
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:

169.393 171.312 56.783 88.03 56.118
56.666 86.571 169.393 -999.25
169.393 171.312 56.783 88.03 56.118
56.666 86.571 169.393 -999.25
169.393 171.312 56.783 88.03 56.118
56.666 86.571 169.393 -999.25

It goes on that way for 24k lines. What I need to do is bring the second line up after the first one so it looks like:

169.393 171.312 56.783 88.03 56.118 56.666 86.571 169.393 -999.25
169.393 171.312 56.783 88.03 56.118 56.666 86.571 169.393 -999.25
169.393 171.312 56.783 88.03 56.118 56.666 86.571 169.393 -999.25

The kicker thing is that there is no way to sort the two apart by the numbers, assume the numbers are completely random. The only way I can think is to try and sort by number of fields in each line. Is there any other way this can be done, or can someone help me figure out how to sort them by number of fields (4 vs 5).

Thanks

Blueheed
# 2  
Old 03-23-2006
Doh

Well, now don't I feel like a fool. I spend an hour trying to do it, can't, and then post asking for help. Two minutes later I figure it out.

If anyone cares to know, I simply printed all records with NF > 4 and NF <5, so I'd have two files with the 4 field and 5 field records. From here I can combine them with join.

Thanks anyways.

Blueheed
# 3  
Old 03-23-2006
Code:
paste -d ' ' - - < myFile

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. 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

4. 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

5. Shell Programming and Scripting

awk and combining lines to stdout

I am trying to come up with a good approach to taking a file and only printing 10 columns. The input file has duplicate lines but only the 6th column has real value. I just need to combine the lines and output 1 line per example file: 1 2.0765 AA 10 0.6557 ..... 1 2.0765 AA 10 0.6655 ..... 2... (12 Replies)
Discussion started by: mykey242
12 Replies

6. Shell Programming and Scripting

Combining many lines to one using awk or any unix cmd

Combining many lines to one using awk or any unix cmd Inputfile: Output : Appreciate help on this. (14 Replies)
Discussion started by: pinnacle
14 Replies

7. Shell Programming and Scripting

Combining two text lines into one

Here is the sample file: 646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset. 647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...) 704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted. I want to combine every non-numbered line... (4 Replies)
Discussion started by: mfavero
4 Replies

8. Shell Programming and Scripting

combining lines between 2 pattern using awk

Hi I am fairly new to shell scripting i have some file with outout 1011 abc fyi 6.1.4.5 abr tio 70986 dfb hji 4.1.7 ....some text 111114 i have to format this text to 1011 abc fyi 6.1.4.5 abr tio 70986 dfb hji 4.1.7 ....some text 111114 (3 Replies)
Discussion started by: shell.scriptor
3 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