Appending Consecutive lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending Consecutive lines
# 1  
Old 07-11-2004
Data Appending Consecutive lines

Hi,

I have a file containing a single field on every row. What I need is to append one on to the end of another, e.g.

The input file looks like this:

nnnnn
mmmmmm

nnnnn
mmmmmm

I need it to look like this:

nnnnn mmmmmm

nnnnn mmmmmm

Any ideas would be much appreciated, Thanks Smilie
# 2  
Old 07-12-2004
Try...

paste -d" " - - < infile > outfile

Or...

awk -v RS="" '{$1=$1};1' infile > outfile
# 3  
Old 07-14-2004
Hi Ygor,

Thanks for this. The paste command is the one that works for me. The awk script outputs just one consecutive line but this might be how I've created my file...

Cheers, pondlife. Smilie
# 4  
Old 07-15-2004
Power

Dear Ygor;

Can you please explain in some words the syntax you wrote??
specially the past command

i like your ways guys
# 5  
Old 07-15-2004
For the AWK command.....

If my input file contains....
Code:
nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm

I use the command
Code:
awk 'BEGIN{RS="\n\n"} {printf("%s %s\n", $1, $2)}' infile > outfile

to produce the output
Code:
nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm

Cheers
ZB
# 6  
Old 07-15-2004
zazzybob,

Does this work on your file?

awk -v RS="" '{$1=$1};1' infile
# 7  
Old 07-15-2004
Quote:
Originally posted by Ygor
zazzybob,

Does this work on your file?

awk -v RS="" '{$1=$1};1' infile
Yes it does - I'm not too sure how the OP has his file constructed - I constructed mine exactly as per his original post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep three consecutive lines if each lines contains certain string

say we have : 2914 | REQUEST | whatever 2914 | RESPONSE | whatever 2914 | SUCCESS | whatever 2985 | RESPONSE | whatever 2986 | REQUEST | whatever 2990 | REQUEST | whatever 2985 | RESPONSE | whatever 2996 | REQUEST | whatever 2010 | SUCCESS | whatever 2013 | REQUEST | whatever 2013 |... (7 Replies)
Discussion started by: Saumitra Pandey
7 Replies

2. Shell Programming and Scripting

Removing 3 consecutive lines from script

Hi I need to remove three consecutive lines of code which appear multiple times during a script. Two of the lines also appear in other parts of the scripts and need to stay so I can't strip out the code per se - It needs to be the exact three lines. Hope that makes sense ! Any help much... (5 Replies)
Discussion started by: Grueben
5 Replies

3. UNIX for Dummies Questions & Answers

Matching two patterns in the consecutive lines

Hi Experts I need to match 2 patterns consecutively and display 25 lines after that. 1st one - Error 2nd one - End string ( comes along with the pattern one) 3rd one - error Logic grep "ERROR OCCURRED :" trace.log | awk -v "ES=:" -v "SS=java.lang.NullPointerException" '{ if($NF ~... (8 Replies)
Discussion started by: senthil.ak
8 Replies

4. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

5. Shell Programming and Scripting

Merge two non-consecutive lines

Hello - First post here. I need help combining two lines that are non-consecutive in a file. Using sed, awk or perl preferably. So the file looks as follows. Please note, the "Line#:" is there only for reference. The lines can only be distinguished by whether they have "start" or "done" in... (2 Replies)
Discussion started by: munkee
2 Replies

6. Shell Programming and Scripting

how to delete two consecutive lines from the file

Hi guys I am deleting a unique line from the file and also need to remove the line above it which is NOT unique and servers as a record separator. Here is an example: # 101 803E 823F 8240 # 102 755f 4F2A 4F2B # 290 747D 0926 0927 # 999 8123 813E ... (5 Replies)
Discussion started by: aoussenko
5 Replies

7. Shell Programming and Scripting

look for two consecutive lines in all text files

How to get (a list of) all the text files in the current directory and subdirectories which has the following two consecutive lines: ctrl_end_date=2009 ctrl_process=EXPIRED OR ctrl_end_date=2010 ctrl_process=EXPIRED i.e. (ctrl_end_date=2009 OR ctrl_end_date=2010) AND ctrl_process=EXPIRED... (6 Replies)
Discussion started by: albertkao
6 Replies

8. UNIX for Dummies Questions & Answers

want to merge two consecutive lines.

Hi All, I want to merge two consecutive lines. Currently the output is :--> crmplp1 cmis461 No Online cmis462 No Offline crmplp2 cmis462 No Online cmis463 No ... (6 Replies)
Discussion started by: pank29
6 Replies

9. UNIX Desktop Questions & Answers

How to concatenate consecutive lines

I have a few lines like -- feature 1, subfeat 0, type 3, subtype 1, value 0, -- feature 1, subfeat 0, type 1, subtype 1, value 0, I would like to concatenate the... (1 Reply)
Discussion started by: shivi707
1 Replies

10. UNIX for Dummies Questions & Answers

Cutting n consecutive lines from a file...

Hi, I have this problem of separating 10 consecutive lines from a file, say starting from 21 to 30... I have used a filter like this.. head -n 30 myfile | tail -n 10 Is there a simpler way than this? (2 Replies)
Discussion started by: Vishnu
2 Replies
Login or Register to Ask a Question