Script to compare pattern and print a different pattern in each line | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-01-2013
Serena Serena is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 1 March 2013, 5:23 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 03-01-2013
panyam panyam is offline Forum Advisor  
Registered User
 
Join Date: Sep 2008
Last Activity: 24 July 2014, 3:48 AM EDT
Posts: 1,156
Thanks: 20
Thanked 104 Times in 99 Posts
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 ).
Sponsored Links
    #3  
Old 03-01-2013
Serena Serena is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 1 March 2013, 5:23 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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 06:40 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to match a pattern and print only the pattern and after that Serena Shell Programming and Scripting 14 03-01-2013 05:14 AM
Grep the word from pattern line and update in subsequent lines till next pattern line reached rbalaj16 Shell Programming and Scripting 5 06-18-2012 04:39 AM
Need one liner to search pattern and print everything expect 6 lines from where pattern match made chidori Shell Programming and Scripting 8 03-15-2012 11:46 AM
Print a pattern between the xml tags based on a search pattern oky Shell Programming and Scripting 13 03-21-2011 01:03 PM
Script to print first and last line have two pattern nitinkgoud Shell Programming and Scripting 4 11-10-2009 06:16 PM



All times are GMT -4. The time now is 11:32 PM.