select entry from consecutive line awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting select entry from consecutive line awk
# 1  
Old 04-25-2012
select entry from consecutive line awk

Hi folks,

I have a file with four columns that looks like the following (tab separated)
1 1 1 a
2 2 2 b
3 3 3 c
4 4 4 d

I would like to create a file with always 4 columns but where the third entry corresponds to the thirst entry of the next line and so on, to get the following
1 1 2 a
2 2 3 b
3 3 4 c
...

any hint on how to deal with that using awk ?

Many thanks,
# 2  
Old 04-25-2012
Hi klebsiella,

How would be output of last line?
# 3  
Old 04-25-2012
Hi birei,

Thanks for the fast reply,

In that case we have to forget the last line. I only pick the value of the third column from it.
# 4  
Old 04-25-2012
Code:
$ awk 'NR>1{print a,b,$3,d}{a=$1;b=$2;d=$4}' file
1 1 2 a
2 2 3 b
3 3 4 c

# 5  
Old 04-25-2012
Hi neutronscott,

This does exactly what I want,

I initially went for more complicated stuf with "getline" and so on.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to code every 2 consecutive entries as single entry

All, I come across the below requirement and my search on the previous posts did not result into any matches. I have one column of data from a csv file like below. And I need to add additional column based on string count in first column. Given column, Required column, Other columns A, 1,... (8 Replies)
Discussion started by: ks_reddy
8 Replies

2. Shell Programming and Scripting

Delete a specific line containing non consecutive number?

Dear Specialists, I have following data 1 1 2 2 2 3 3 3 6 4 3 4 5 4 9 6 5 11 7 6 7 and I would like to obtain data like below 1 1 2 2 2 3 4 3 4 7 6 7 (2 Replies)
Discussion started by: Ryan Kim
2 Replies

3. Shell Programming and Scripting

awk Help: Filter Multiple Entry & print in one line.

AWK Gurus, data: srvhcm01 AZSCI srvhcm01 AZSDB srvhcm01 BZSDB srvhcm01 E2QDI31 srvhcm01 YPDCI srvhcm01 YPDDB srvhcm01 UV2FSCR srvhcm01 UV2FSBI srvhcm01 UV2FSXI srvhcm01 UV2FSUC srvhcm01 UV2FSEP srvhcm01 UV2FSRE srvhcm01 NASCI srvhcm01 NASDB srvhcm01 UV2FSSL srvhcm01 UV2FSDI (7 Replies)
Discussion started by: rveri
7 Replies

4. Shell Programming and Scripting

How can I get the 3 consecutive appearances of a line?

File 1 aaa ccc fff File 2 aaa bbb ddd File 3 aaa bbb eee File 4 (4 Replies)
Discussion started by: Misa-Misa
4 Replies

5. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

6. UNIX for Dummies Questions & Answers

how to print out consecutive two line from a text file

the text file like below's input: aaaaaaaaafdsfsda sdfsadfasdfasfds sdfadsf asdfadf asdfa adfsfsafas sdfsfafads asdfasdfsa I want to print out consecutive two line output: aaaaaaaaafdsfsda (1 Reply)
Discussion started by: vincent_W
1 Replies

7. Solaris

How to select last 7 days entry from SULOG or LAST command

Hi All, I need to get last 7 days log entries from sulog. The same has to be done for the last command. for ex: when i search for a user "abc" in sulog, i only want to check his entries for the last 1 week. The same has to be done for last command. Can anyone suggest some tips. ... (0 Replies)
Discussion started by: navdeepan
0 Replies

8. Shell Programming and Scripting

awk program to select a portion of a line

Hi all, I am new to awk programs.I have a file like this vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd... (3 Replies)
Discussion started by: anju
3 Replies

9. Shell Programming and Scripting

grab next consecutive line or lines

Hello i'm writting a krn shell that will find the letter F and I would like to grab everything from F till 0:00. Is there a sed or awk command that i could use. Thank you. File is looks like this. 11/12 xxx xxxx xxx F xxxx xxxx some info entered here some info entered here xxxx... (1 Reply)
Discussion started by: wisher115
1 Replies

10. Shell Programming and Scripting

awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line . Any help is appreciated. thanks arif (4 Replies)
Discussion started by: mab_arif16
4 Replies
Login or Register to Ask a Question