Piping grep into awk, read the next line using grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Piping grep into awk, read the next line using grep
# 1  
Old 12-09-2013
Piping grep into awk, read the next line using grep

Hi,

I have a number of files containing the information below.

"""""
Fundallinfo
6.3950 14.9715 14.0482
"""""

I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and just use grep to find the string.

something like:

grep "Fundallinfo" | awk '{print $1,2 or 3} ') but for the line after Fundallinfo.

Thank you.

Paul
# 2  
Old 12-09-2013
Code:
$ awk '/Fundallinfo/{getline;print}' input
6.3950 14.9715 14.0482

# 3  
Old 12-10-2013
Code:
#!/usr/bin/env perl
use strict;
use warnings;

while( my $line = <> ){	
	if ( $line =~ /Fundallinfo/ ){
		$line = <>;
		print $line ; 
	}
}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Piping to grep with pbpaste

cat file 1 aaa 2 bbb 3 ccc 4 ddd In TextEdit, I then copy the characters “ccc” to the clipboard. The problem is that the following command gives no output: bash-3.2$ pbpaste | grep - file Desired output: 3 ccc What should the syntax be for that command? I am using MacOS El... (3 Replies)
Discussion started by: palex
3 Replies

2. Shell Programming and Scripting

Piping through grep/awk prevents file write

So, this is weird... I'm running this command: iotop -o -P -k -bt -d 5 I'd like to save the output relelvant to rsyslogd to a file, so I do this: iotop -o -P -k -bt -d 5 | grep rsyslogd >> /var/log/rsyslogd Nothing is written to the file! I can write the full output to the file: ... (2 Replies)
Discussion started by: treesloth
2 Replies

3. Shell Programming and Scripting

piping from grep to awk without intermediate files

I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output which was given by the grep. sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* Output: ... (6 Replies)
Discussion started by: siteregsam
6 Replies

4. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (6 Replies)
Discussion started by: frymor
6 Replies

5. Ubuntu

Piping with grep

Hi everybody, I have a big file with blast results (if you know what this means, otherwise look at it just as a text file with a specific form). I am trying to extract some ids from within this file, which have certain parameters. For example, some Of my IDs have the term 'No hit results'... (1 Reply)
Discussion started by: frymor
1 Replies

6. Shell Programming and Scripting

Read content between xml tags with awk, grep, awk or what ever...

Hello, I trying to extract text that is surrounded by xml-tags. I tried this cat tst.xml | egrep "<SERVER>.*</SERVER>" |sed -e "s/<SERVER>\(.*\)<\/SERVER>/\1/"|tr "|" " " which works perfect, if the start-tag and the end-tag are in the same line, e.g.: <tag1>Hello Linux-Users</tag1> ... (5 Replies)
Discussion started by: Sebi0815
5 Replies

7. UNIX for Dummies Questions & Answers

Piping GREP

Hi, I need to use a double grep so to speak. I need to grep for a particular item say BOB and then for each successful result I need to grep for another item say SMITH. I tried grep "BOB" filename | grep "SMITH" but it does not seem to work. I can achieve my desired result using an... (12 Replies)
Discussion started by: mojoman
12 Replies

8. Shell Programming and Scripting

cat file1 read line-per-line then grep -A 15 lines down in fileb

STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile # THIS IS THE MAIN FILE. cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address... (6 Replies)
Discussion started by: irongeekio
6 Replies

9. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

10. Shell Programming and Scripting

Read file then grep the line

Dear all, I am reading a file that has 1 column. While reading I must find the line references from the another file. The following shell doesn't works. Please help #!/bin/bash while read filename; do grep ${filename} fs_full.dat >> unprocfull.dat; done < unproc.dat But when... (2 Replies)
Discussion started by: mr_bold
2 Replies
Login or Register to Ask a Question