print pattern line +2 without tabs or brackets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print pattern line +2 without tabs or brackets
# 1  
Old 04-15-2008
print pattern line +2 without tabs or brackets

This works, but its messy. Any suggestions for a elegant solution? :-

Code:
me@myserver $ head zoneAttachOutfile
These packages installed on the source system are inconsistent with this system:
        SUNWsmbac: version mismatch
                (11.9.0,REV=2002.03.02.00.35)
                (11.10.0,REV=2005.01.08.05.16)
        SUNWsmbau: version mismatch
                (11.9.0,REV=2002.03.02.00.35)
                (11.10.0,REV=2005.01.08.05.16)
These packages installed on this system were not installed on the source system:
        SUNWtcsh (11.10.0,REV=2005.01.08.05.16)
        SUNWtltkm (3.7.2,REV=10.2004.12.17)

me@myserver $ pkgMismatched=SUNWsmbac ## later this will be a variable in a loop

me@myserver $ let reqVersionLine="`grep -n $pkgMismatched zoneAttachOutfile | head -1 | cut -f1 -d:`+2" ## resolves to 4 in above example

me@myserver $ requiredVersion=`sed -n "${reqVersionLine}p" zoneAttachOutfile | tr -d '()\t'`

me@myserver $ echo $requiredVersion
11.10.0,REV=2005.01.08.05.16


Regards Rep

Last edited by Yogesh Sawant; 04-16-2008 at 12:36 AM.. Reason: added code tags
# 2  
Old 04-16-2008
Try...
Code:
requiredVersion=$(awk -F '[)(]' "/$pkgMismatched/"'{getline;getline;print $2}' zoneAttachOutfile)

# 3  
Old 04-16-2008
Thanks Ygor, that was much neater than what i was doing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies

2. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

3. UNIX for Advanced & Expert Users

To print from the first line until pattern is matched

Hi I want to print the line until pattern is matched. I am using below code: sed -n '1,/pattern / p' file It is working fine for me , but its not working for exact match. sed -n '1,/^LAC$/ p' file Input: LACC FEGHRA 0 LACC FACAF 0 LACC DARA 0 LACC TALAC 0 LAC ILACTC 0... (8 Replies)
Discussion started by: Abhisrajput
8 Replies

4. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

5. Shell Programming and Scripting

Print only next pattern in a line after a pattern match

I have 2013-06-11 23:55:14 1Umexd-0004cm-IG <= user@domain.com I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <= ie only print user@domain.com (7 Replies)
Discussion started by: anil510
7 Replies

6. Shell Programming and Scripting

Script to compare pattern and print a different pattern in each line

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ......qrt: .... .......xyz: abz: ......qrt: ... I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get... (2 Replies)
Discussion started by: Serena
2 Replies

7. Shell Programming and Scripting

Print Line if next line Match a pattern

Hi All, Does anyone know how to print 1H1A....... in peal script print line ^1H1A....... if next line equal 5R0RECEIPT.... Thank for help:D Cat st.txt 1H1A-IN-11-5410-0009420|1010047766|dsds|1|N|IN|IN|000000|1||N|<<<line match 5R0RECEIPT| 5R0RECEIPT|... (2 Replies)
Discussion started by: kittiwas
2 Replies

8. Programming

Print specific pattern line in c++

Input file: @HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC +HWI-BRUNOP1_header_1 TNTTJTTTETceJSP__VRJea`_NfcefbWe Desired output file: >HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC >HWI-BRUNOP1_header_2... (10 Replies)
Discussion started by: cpp_beginner
10 Replies

9. UNIX for Dummies Questions & Answers

MATCH A PATTERN AND PRINT A LINE ABOVE AND BELOW

Dear All, Hv a very specific requirement. I have a very large text file and in which I have to match a pattern and insert a line above and below. Eg: My file cat test date1 date2 date3 date4 I need to match 'date3' and insert "Reminder1" above date3 and insert 'reminder2'... (4 Replies)
Discussion started by: gokulj
4 Replies

10. Shell Programming and Scripting

match a pattern and print the line once

Hi, I have a xml file <cisco:name> <cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:ehNm>/shelf=1</cisco:ehNm> <cisco:subname> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:sptp>Cisco PortA Series</cisco:sptp> ... (11 Replies)
Discussion started by: bhagirathi
11 Replies
Login or Register to Ask a Question