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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to compare pattern and print a different pattern in each line
# 1  
Old 03-01-2013
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: [1234] abz: [1234]......qrt: [2312]....
.......xyz: [1231] abz: [2414]......qrt: [1231]...

I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get the required output using awk and split it into columns.
The value before the ":' is always constant, the value in the brackets only keep changing.
I need an option which prints in the following manner based on what is being grepped.
it should be a one liner as it is part of a much bigger script, and it should be able to compare the value in the brackets for "xyz:" and "abz:" and if it is the samee then it should print "qrt: [2312]"

In the above example lines the output should be only "qrt: [2312]" as that is the only line with the matching value in the bracket of "xyz:" and "abz:".

Please help

Thanks
# 2  
Old 03-01-2013
hi Senera,

This is the second time you are posting the same question again which is against the forum rules.

Also, you are changing the input specification every time ( please check your earlier post on the same subject ).
# 3  
Old 03-01-2013
I need a one liner because it is part of a bigger script as I have mentioned. I am not sure what do you mean by homework. I am writing this script to gather a lot of different variables, and this is just one of the variable.

A solution and the number of lines in the code is also equally important to me as I will be filtering a lot of other parameters before i come to this part of comparison, and also do a lot more filtering and calculation.

Earlier when the position of the variables in the log files weren't changing so i used to use a simple awk comparison like below,
Code:
awk '$2!=$5{print $9}'

I am not an expert in awk, so I am asking help on this.

And finally sorry for starting another thread, I wasn't sure if it has to be one question in each thread, so I started a new one.

Most of the time, I search and try for solutions from the existing threads, but i couldn't find anything close to my problem and I really need some help in getting this solution.

Thanks

Last edited by Franklin52; 03-01-2013 at 07:40 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

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

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

5. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

6. Shell Programming and Scripting

Script to match a pattern and print only the pattern and after that

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: ...... .......xyz: abz: ..... I have tried using awk and cut, bu the position of these values keep changing, so I can use awk and split it into columns. ... (14 Replies)
Discussion started by: Serena
14 Replies

7. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

8. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

9. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

10. Shell Programming and Scripting

Script to print first and last line have two pattern

Hello Guys, I have file like aaa bbb Line 1 cc dd Ser Nu 11223 ee ff Line 2 hh hh Ser Nu 44556 ii jj I need to match line starting with Line and Ser and only display them like Line 1 Ser Nu 11223 | Line 2 Ser Nu 44556 (4 Replies)
Discussion started by: nitinkgoud
4 Replies
Login or Register to Ask a Question