Sponsored Content
Top Forums Shell Programming and Scripting grep the line only if next line matches Post 302124194 by pbsrinivas on Friday 29th of June 2007 05:35:02 AM
Old 06-29-2007
grep the line only if next line matches

Hi

I have an Input of following sort

AAAA:
ProgName="PROGRAM"
BBBB:
ProgName="BBBBBB"
CCCC:
DDDD:
ProgName="PROGRAM"
SSSS:
ProgName="PROGRAM"
ZZZZ:
ProgName="PROGRAM"

I want to find the Lines which are followed by ProgName="PROGRAM"

Out Put
AAAA:
DDDD:
SSSS:
ZZZZ:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending Text To Each Line That Matches Grep

I'm currently digging for a way to append a line to a text file where each line begins with the word "setmqaut". This is a continuation of my IBM MQSeries backup script I'm working on to make my life a little easier. What I would like to do is have each line that looks like this: setmqaut -m... (4 Replies)
Discussion started by: sysera
4 Replies

2. UNIX for Advanced & Expert Users

Inserting a line before the line which matches the patter

Hi Is there any command where we can insert a line "2|||" before every line starting with "3|" my input is as follows 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 2|EN_GB||Electrogalvanize 0.5 m2 ( Renault ) 1|ETG|12345 3|88.51|||GBP|| desired output... (10 Replies)
Discussion started by: laxmi131
10 Replies

3. 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

4. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

5. UNIX for Dummies Questions & Answers

if line matches then

I have a file that I need to read each line and see if the line begins with a certain keyword. I can't seem to find something that works. #!/bin/ksh # while read i do if ] then echo "SE2 WORKS" elif ] then echo "CISCO1 WORKS" fi done < tmp/diff The file looks something like SE1 SE2... (2 Replies)
Discussion started by: numele
2 Replies

6. Shell Programming and Scripting

How to substitute a line that matches an expression with another line

I need some help. I have a file (all.txt) whereby I want to substitute using sed/awk all lines that matches an expression with another line with different expression i.e subtitute expression, database_id: filename; WITH database_id: PY; There are many occurrences of the expression... (4 Replies)
Discussion started by: aimsoft
4 Replies

7. UNIX for Dummies Questions & Answers

print line that matches and next line, too

I'm using sh on hp-ux and want to find / print a line that matches 132.101- and the next line, too. grep -A isn't supported on hp-ux, so I'm trying awk and sed. The code below works but only prints the first occurence. I need all matches from the file. awk... (2 Replies)
Discussion started by: Scottie1954
2 Replies

8. Shell Programming and Scripting

Using regex's from file1, print line and line after matches in file2

Good day, I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after. file1: file2: Output: I can match a regex and print the line and line after awk '{lines = $0} /Macrosiphum_rosae/ {print lines ; print lines } ' ... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

9. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

10. Linux

Print line 1 if line 3 matches of the output

Hi I want to extend following command so that on the basis of "Branch: ****" on the third line I can grep and print name of the file on the first line. cat .labellog.emd | grep DA2458A7962276A7E040E50A0DC06459 | cut -d " " -f2 | grep -v branch_name | xargs -I file <command to describe> file ... (1 Reply)
Discussion started by: ezee
1 Replies
DIFF3(1)							   User Commands							  DIFF3(1)

NAME
diff3 - compare three files line by line SYNOPSIS
diff3 [OPTION]... MYFILE OLDFILE YOURFILE DESCRIPTION
Compare three files line by line. -e --ed Output unmerged changes from OLDFILE to YOURFILE into MYFILE. -E --show-overlap Output unmerged changes, bracketing conflicts. -A --show-all Output all changes, bracketing conflicts. -x --overlap-only Output overlapping changes. -X Output overlapping changes, bracketing them. -3 --easy-only Output unmerged nonoverlapping changes. -m --merge Output merged file instead of ed script (default -A). -L LABEL --label=LABEL Use LABEL instead of file name. -i Append `w' and `q' commands to ed scripts. -a --text Treat all files as text. -T --initial-tab Make tabs line up by prepending a tab. --diff-program=PROGRAM Use PROGRAM to compare files. -v --version Output version info. --help Output this help. If a FILE is `-', read standard input. AUTHOR
Written by Randy Smith. REPORTING BUGS
Report bugs to <bug-gnu-utils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This program comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of this program under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. SEE ALSO
The full documentation for diff3 is maintained as a Texinfo manual. If the info and diff3 programs are properly installed at your site, the command info diff should give you access to the complete manual. diffutils 2.8.1 April 2002 DIFF3(1)
All times are GMT -4. The time now is 09:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy