Printing the next line side by to the current line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Printing the next line side by to the current line
# 1  
Old 06-04-2014
Printing the next line side by to the current line

Help,
I have a text file which looks like

Code:
disco 5674536
3456 jambo

disco 453678
4578 jambo

I would like to have an output which looks like below

Code:
disco 3456 disco 4578

So, its greping disco intitially and printing the first column of the immediate next line side to it.Is it possible?

Thanks in advance for your help

Moderator's Comments:
Mod Comment
using GUI for code tags, after you added code tags, you insert in between your content...
Regards

Last edited by vbe; 06-04-2014 at 05:32 AM.. Reason: Code not working.
# 2  
Old 06-04-2014
Code:
$ awk '/disco/{s = $1; getline; printf s OFS $1 OFS}END{printf RS}'  file
disco 3456 disco 4578

# 3  
Old 06-04-2014
Code:
awk 'NF{print $1} END{printf RS}' ORS=" " file

# 4  
Old 06-04-2014
Akshay and Scritinizer,

Many Thanks for the code. How can I modify the code if I wish to have output like

disco 3456
disco 4578

Thanks in advance,

Last edited by Indra2011; 06-04-2014 at 06:08 AM.. Reason: code
# 5  
Old 06-04-2014
Try:
Code:
awk '{print $1, $3}' RS= file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run 2 python scripts at the same time side by side on the same line?

Could I run 2 python scripts at the same time side by side output on the same line in this same format but with scripts? from itertools import izip_longest with open("file1") as textfile1, open("file2") as textfile2: for x, y in izip_longest(textfile1, textfile2, fillvalue=""): x =... (4 Replies)
Discussion started by: bigvito19
4 Replies

2. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

3. Shell Programming and Scripting

Copy Column Value Of Next Line Into Current Line

Hello All, I am looking for help to achieve the following: Here is the data set 1757890237|42|55570025|1468796400|0 1757890237|32|55570025|1471474800|0 1757890237|54|55570025|1474153200|1476745200 1757890237|34|55570026|1468796400|0 1757890237|44|55570026|1471474800|0... (7 Replies)
Discussion started by: angshuman
7 Replies

4. Shell Programming and Scripting

Append Next line with current Line bassed on condition

Hi, I have an XML file and I am tring to extract some data form it, after lot of data cleaning process, I ended up with an issue, and need your urgent support. my current input data in below format: <Node>xxxxxx <Node>yyyyy</Node> <Node>zzzzzz <Node>12345</node> I need... (9 Replies)
Discussion started by: rramkrishnas
9 Replies

5. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

6. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

7. Shell Programming and Scripting

printing 3 files side by side based on similar values in rows

Hi I'm trying to compare 3 or more files based on similar values and outputting them into 3 columns. For example: file1 ABC DEF GHI file2 DEF DER file3 ABC DER The output should come out like this file1 file2 file3 ABC ABC (4 Replies)
Discussion started by: zerofire123
4 Replies

8. Shell Programming and Scripting

Vi Editor - How to paste the line concatenated with current line

I generally use yy to copy a line and then p to paste the line at end of current line. But is there a way to paste the copied line in concatenation with the current line with out going to next line. (3 Replies)
Discussion started by: paragkalra
3 Replies

9. Shell Programming and Scripting

Need help in sed command [ printing a pattern + its line no or line no alone ]

Hello friends, Only very recently i started learning sed command...an i found that sed is faster in finding the patterns than some of my scripts that uses grep to check the patten inside a file using line by line search method which is time consuming. The below script... (4 Replies)
Discussion started by: frozensmilz
4 Replies

10. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies
Login or Register to Ask a Question