get data from next line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers get data from next line
# 1  
Old 12-04-2007
get data from next line

Hi using awk I know I can get all the lines with gold from a file called "gold.txt" like the one below:

gold 1 1986 USA American Eagle
gold 1 1908 Austria-Hungary Franz Josef 100 Korona
silver 10 1981 USA ingot
gold 1 1984 Switzerland ingot
bronze 1 1979 RSA Krugerrand
gold 0.5 1981 RSA Krugerrand
platinum 0.1 1986 PRC Panda
silver 1 1986 USA Liberty dollar
gold 0.25 1986 USA Liberty 5-dollar piece
silver 0.5 1986 USA Liberty 50-cent piece
silver 1 1987 USA Constitution dollar
gold 0.25 1987 USA Constitution 5-dollar piece
gold 1 1988 Canada Maple Leaf

with

awk '/gold/' coins.txt

however it is driving me crazy trying to figure out how to get the data from the next line after those with gold in it.

Many thanks,

Adam

Last edited by whamchaxed; 12-04-2007 at 06:27 PM.. Reason: First time, pressed enter trying to do something else before ready
# 2  
Old 12-04-2007
Hm, very interesting, what are you intending?
# 3  
Old 12-04-2007
maybe set a flag on finding gold.......


/$1~/gold/{gold=1}
/gold=1/{print; gold=0}
# 4  
Old 12-04-2007
intending

I have log files which has the single word 'Text' on the line prior to the actual text I need. I tried using

HTML Code:
grep -n PATTERN FILE
to get the line numbers with Text in it but that led to more problems as I tried to get the numbers and then grab those particular lines. I normally work with MATLAB and think my approach is all wrong. Been going round in circles all day.

I'm afraid I didn't quite get the setting of a flag, in no setup of the path can I get this to find the file gold.txt

Adam
# 5  
Old 12-04-2007
Code:
awk '/gold/{getline;print}' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.

With sed:

Code:
sed -n '/gold/{n;p;}' filename


Last edited by radoulov; 12-04-2007 at 07:08 PM.. Reason: corrected
# 6  
Old 12-04-2007
thanks.. that works

Still trying to figure out how it works but thanks.

Adam
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Take 10 latest line data

Good day for us. I want to ask what is the manner to count total of spesific character or string in 10 latest line. I mean from Latestline - 10 line until Latest line. Example : If the latest line of my file is 455th line, I just want to count total of spesific string from line 446th to 455th.... (5 Replies)
Discussion started by: weslyarfan
5 Replies

2. UNIX for Dummies Questions & Answers

How to find and get data from line.?

i have data "23:2737757981:GatewayService-5-12-1.CWD2N.awn.com;1365594072;74383" in my file how to search "CWD2N" and get data output => "CWD2N.awn.com;1365594072;74383" (3 Replies)
Discussion started by: krai
3 Replies

3. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

4. Shell Programming and Scripting

Help in adding a data after a particular line of data in a file.

Hi.. I'm into a bump after trying to solve this prob.. i've a file with contents like below. <blankline> 'pgmId' : 'UNIX', 'pgmData' : 'textfile', 'author' : 'admin', ....... Now i'm trying to insert a new data after pgmId. so the final output will be... (7 Replies)
Discussion started by: arjun_arippa
7 Replies

5. Shell Programming and Scripting

split data by line

I would like break in two line by 'SNAG' Current data: SNAG|M1299063| | | | |0001.|0010.|AC64797|2008-02-18|093730.|YVR|AC64797|2008-02-18-09.37.30.250020|N|30|NO LEAKS OR CRACKS THIS A7 SCK SNAG|M1299063| | | |... (10 Replies)
Discussion started by: javeiregh
10 Replies

6. Shell Programming and Scripting

Modifying data within the same line

My file looks like this But I need to move the frequency value (Freq) to the second position, leaving intact the numbers at the top. The resulting file should look like this Thanks in advance! (3 Replies)
Discussion started by: Xterra
3 Replies

7. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

8. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

9. Shell Programming and Scripting

compare data line by line from a file

Hi there How can I compare data line by line from a file? I need to compare the second value with the fourth to know if they are different. If those values are different, I require to send my first value to the output until the complete file has been read. This is my file: 0 FALSE... (1 Reply)
Discussion started by: loperam
1 Replies

10. Shell Programming and Scripting

Extracting data from each line

Hi All I have one file aa.txt like this Change 172453 on 2006/04/26 10:45:45 by cm@cm-ixca-cm-build23 'cmbuild: ixweb-3.10.28.110 ' Change 172362 on 2006/04/26 08:58:47 by cm@cm-ixca-cm-build23 'build failed: ixweb-3.10.28.109' Change 172299 on 2006/04/26 07:39:08 by... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question