Match and Print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match and Print
# 1  
Old 01-25-2012
Match and Print

tr td td

Last edited by parthmittal2007; 01-25-2012 at 08:57 AM.. Reason: Its not the code its the content written in file.
# 2  
Old 01-25-2012
Looking for something like this?
Code:
$ cat inputfile
<tr>
    <td><A HREF="http://111.111.111.111:9999/">270A_NS_5 Eligibility Gateway</A></td>
    <td>NNNNN003_270A_NS_5</td>
    <td>111.111.111.111</td>
    <td>9999</td>
    <td><p align="center">Yes</td>
    <td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
    <td>01/25/12 06:24:43</td>
    <td><p align="center">0</td>
    <td>Direct (NNNNN)</td>
</tr>
<tr>
    <td><FONT COLOR="BLUE"><B>Up</B></FONT></td>
    <td>01/25/12 06:24:43</td>
    <td><p align="center">0</td>
</tr>
<tr>
    <td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
    <td>01/25/12 06:24:43</td>
    <td><p align="center">10</td>
</tr>
$
$ perl -lne '(/GREEN/)&&($f=1);if(/center">([0-9]+?)</ && $f==1){print "$1";$f=0}' inputfile
0
10
$


Last edited by balajesuri; 01-25-2012 at 08:10 AM..
# 3  
Old 01-25-2012
Code:
cat file |grep -A 2 GREEN |tail -1   |awk '{print int ($NR)}'

Will work if the value you are looking for after GREEN comes after two lines like in your sample...
# 4  
Old 01-25-2012
I give you the whole content in the file
The content look like this

Code:
<tr>
    <td><A HREF="http://111.11.111.95:1111/">999B_FF_4 Partners and Lahey Eligibility Gateway</A></td>
    <td>NNNNNN_999B_FF_4</td>
    <td>111.11.111.95</td>
    <td>1111</td>
    <td><p align="center">Yes</td>
    <td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
    <td>01/25/12 02:53:48</td>
    <td><p align="center">10</td>
    <td>Direct (NNNNN)</td>
  </tr>


Last edited by methyl; 01-25-2012 at 01:44 PM.. Reason: please use code tags
# 5  
Old 01-25-2012
Code:
perl -ne 'if ( /(GREEN)/ ) { print "$1 "; $f = 1 }
if ( /center">([0-9]+?)</ && $f == 1 ) { print "$1\n"; $f = 0 }' inputfile

This User Gave Thanks to balajesuri For This Post:
# 6  
Old 01-25-2012
@balajesuri
You are master..

---------- Post updated at 08:22 AM ---------- Previous update was at 07:31 AM ----------

@balajesuri..
can you please explain me the line
if ( /center">([0-9]+?)</ && $f == 1 ) { print "$1\n"; $f = 0 }
I didn't get it clearly
# 7  
Old 01-25-2012
/center">([0-9]+?)</ ==> Match string containing 'center">(some numbers)<'. Since the numbers are enclosed in round parenthesis, they're back referenced using $1. (print "$1\n")
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

2. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Match the value & print lines from the match

Hello, I have a file contains two columns. I need to print the lines after “xxx” so i'm trying to match "xxx" & cut the lines after that. I'm trying with the grep & cut command, if there any simple way to extract this please help me. Sample file : name id AAA 123 AAB 124 AAC 125... (4 Replies)
Discussion started by: Shenbaga.d
4 Replies

4. Shell Programming and Scripting

Print only match pattern

Hi, I want to print the lines from file1 which has the matching pattern from file2 in linux. file1 data is below ----------------- CACA|1234 CA|2345 file2 data is below ----------------- CA NC TX Now I want to print the lines from file1 for the values present in file2. ... (5 Replies)
Discussion started by: ureddy
5 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

AWK match and print

I have thousands of tables compiled in a single txt document that I'm parsing with AWK. Scattered throughout the document in random sections I would like to parse out the sections that look like this: 1 Seq. Descrição do bem Tipo do bem Valor do bem (R$) 2 1 LOCALIZADO ANA RUA PESSEGO N 96... (3 Replies)
Discussion started by: daveyabe
3 Replies

7. Shell Programming and Scripting

match pattern 1 and print or match pattern 2 and print

hi all basically i have file called rules which contain lines like below /usr/bwmgr/utils/bwmgr em1 -x 735 -name user92 -addr 10.10.201.92 -addrmsk 255.255.255.252 -bwout 1024000 -bwin 2048000 -statsdevice user92 -stats /usr/bwmgr/utils/bwmgr em1 -x 45032 -name user246 -addr 10.10.224.246... (2 Replies)
Discussion started by: sb245
2 Replies

8. Shell Programming and Scripting

Match and print particular column

Hi All, I am in need of help. I want to match a value of each row in “file 1” with the value of first row in “file 2” and print out only the columns that match. How can I do it in awk? Any help is greatly appreciated. for example, I have two files: Cat “File 1” ID 3 8 15 Cat “File... (2 Replies)
Discussion started by: newpro
2 Replies

9. Shell Programming and Scripting

how to print all lines from a second match

I am trying to parse iostat output for io issues.. I want to print all lines including second occurance of 'extended' till EOF(end of file). Can we do that using awk or sed one liners or do we need a script for it? (1 Reply)
Discussion started by: kchinnam
1 Replies

10. Shell Programming and Scripting

exact string match ; search and print match

I am trying to match a pattern exactly in a shell script. I have tried two methods awk '/\<mpath${CURR_MP}\>/{print $1 $2}' multipath perl -ne '/\bmpath${CURR_MP}\b/ and print' /var/tmp/multipath Both these methods require that I use the escape character. I am guessing that is why... (8 Replies)
Discussion started by: bash_in_my_head
8 Replies
Login or Register to Ask a Question