Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2012
Registered User
 

Join Date: Dec 2011
Posts: 154
Thanks: 21
Thanked 2 Times in 2 Posts
Find and print Modification

Hi All
I am stuck with a problem and i want your help. I have a file in which content of that file looks like-:

Code:
 <tr>
      <td><A HREF="http://333.33.333.33:3333/">Pan Eligibility</A></td>
      <td>NNNNNNNN_NS</td>
      <td>333.33.333.33</td>
      <td>3333</td>
      <td><p align="center">Yes</td>
      <td><FONT COLOR="GREEN"><B>Down</B></FONT></td>
      <td>01/25/12 02:53:48</td>
      <td><p align="center">1020</td>
      <td>Direct (NNNNN)</td>
    </tr>
   
    <tr>
      <td><A HREF="http://111.11.111.111:9111/">270 Gate</A></td>
      <td>NNNNNNNN_270A</td>
      <td>111.11.111.111</td>
      <td>1111</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">1230</td>
      <td>Direct (NNNNN)</td>
    </tr>
   
    
  <tr>
      <td><A HREF="http://111.11.111.111:1111/">Eligible</A></td>
      <td>NNNNNNNN</td>
      <td>111.11.111.111</td>
      <td>1111</td>
      <td><p align="center">Yes</td>
      <td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
      <td>01/25/12 02:44:36</td>
      <td><p align="center">20</td>
      <td>Direct (NNNNN)</td>
    </tr>
   
    <tr>
      <td><A HREF="http://222.22.222.222:2222/">NS_Display Note </A></td>
      <td>NNNNNNNN_NS</td>
      <td>222.22.222.222</td>
      <td>2222</td>
      <td><p align="center">Yes</td>
      <td><FONT COLOR="GREEN"><B>Down</B></FONT></td>
      <td>01/25/12 06:04:46</td>
      <td><p align="center">100</td>
      <td>Direct (NNNNN)</td>
    </tr>

what i have to do is i have to search in this file the keyword Down and if found. The Script should give the output as follow-:
Output-

Code:
Pan Eligibility Down 1020
NS_Display Note Down 100



Please help me

Last edited by Franklin52; 02-09-2012 at 04:34 AM.. Reason: Please use code tags for code and data samples, thank you
Sponsored Links
    #2  
Old 02-09-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts
Assuming, the format is consistent across!
Code:
awk -F"[><]" '/HREF/{h=$(NF-4)}/Down/{getline;getline; print h,"Down",$(NF-2)}' infile

--ahamed
Sponsored Links
    #3  
Old 02-09-2012
itkamaraj's Avatar
Unix is God
 

Join Date: Apr 2010
Posts: 2,355
Thanks: 21
Thanked 470 Times in 459 Posts

Code:
$ nawk -F"[<>]" '/HREF/{a=$5}/FONT/{b=$7;getline;getline;if(b=="Down"){print a,b,$5}}' test.txt
Pan Eligibility Down 1020
NS_Display Note  Down 100

The Following User Says Thank You to itkamaraj For This Useful Post:
parthmittal2007 (02-09-2012)
    #4  
Old 02-09-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts

Code:
perl -ne '(/<A HREF=\".+?>(.+?)<\/A/) && ($HREF = $1);
    (/FONT COLOR=.+?B>(.+?)<\/B/) && ($FONT = $1);
    (/center\">(.+?)<\/td/) && ($align = $1);
    (/<\/tr>/ && $FONT eq 'Down') && print "$HREF $FONT $align\n";
' input

The Following User Says Thank You to balajesuri For This Useful Post:
parthmittal2007 (02-09-2012)
Sponsored Links
    #5  
Old 02-09-2012
Registered User
 

Join Date: Dec 2011
Posts: 154
Thanks: 21
Thanked 2 Times in 2 Posts
Hi one more case can exist in this that is-:

<tr>
<td><A HREF="http://333.33.333.33:3333/">Pan Eligibility</A></td>
<td>NNNNNNNN_NS</td>
<td>333.33.333.33</td>
<td>3333</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Down</B></FONT></td>
<td>01/25/12 02:53:48</td>
<td><p align="center">1020</td>
<td>Direct (NNNNN)</td>
</tr>

<tr>
<td><A HREF="http://111.11.111.111:9111/">270 Gate</A></td>
<td>NNNNNNNN_270A</td>
<td>111.11.111.111</td>
<td>1111</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">1230</td>
<td>Direct (NNNNN)</td>
</tr>


<tr>
<td><A HREF="http://111.11.111.111:1111/">Eligible</A></td>
<td>NNNNNNNN</td>
<td>111.11.111.111</td>
<td>1111</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
<td>01/25/12 02:44:36</td>
<td><p align="center">20</td>
<td>Direct (NNNNN)</td>
</tr>

<tr>
<td><A HREF="http://222.22.222.222:2222/">NS_Display Note </A></td>
<td>NNNNNNNN_NS</td>
<td>222.22.222.222</td>
<td>2222</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Down</B></FONT></td>
<td>01/25/12 06:04:46</td>
<td><p align="center">100</td>
<td>Direct (NNNNN)</td>
</tr>

<tr>
<td>NPPP</td>
<td>900</td>
<td>555.55.555.55</td>
<td>21</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
<td>01/20/12 07:00:19</td>
<td><p align="center">0</td>
<td>FTP</td>
</tr>

<tr>

<td>Batch</td>
<td>001_835</td>
<td>999.99.999.99</td>
<td>33103</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
<td>01/19/12 23:54:18</td>
<td><p align="center">0</td>
<td>Batch</td>
</tr>


<tr>

<td>Hos</td>
<td>040_837</td>
<td>112.32.96.99</td>
<td>21</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>Up</B></FONT></td>
<td>01/20/12 05:05:10</td>
<td><p align="center">0</td>
<td>Batch</td>
</tr>

<tr>
<td><A HREF="http://444.44.444.44:3333/">Pan Eligibility</A></td>
<td>NNNNNNNN_NS</td>
<td>444.44.444.44</td>
<td>3333</td>
<td><p align="center">Yes</td>
<td><FONT COLOR="GREEN"><B>NO</B></FONT></td>
<td>01/25/12 02:53:48</td>
<td><p align="center">1020</td>
<td>Direct (NNNNN)</td>
</tr>

Here the above code does not work..

---------- Post updated at 06:51 AM ---------- Previous update was at 06:09 AM ----------

Hi balajesuri (Guru)
(condition) && (value assigned) OR (condition) ? ( ) : ( )
Do they both are same things

Last edited by parthmittal2007; 02-09-2012 at 07:31 AM..
Sponsored Links
    #6  
Old 02-09-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts
(expression1) && (expression 2) => Only if expression1 is true, expression2 will be evaluated.

(expression1) && (expression2) || (expression3) => This emulates if (condition) { do this } else { do this }

(condition) ? () : () => This is a ternary operator same as if (condition) { do this } else { do this }
Sponsored Links
    #7  
Old 02-09-2012
Registered User
 

Join Date: Dec 2011
Posts: 154
Thanks: 21
Thanked 2 Times in 2 Posts

Code:
perl -ne '(/<A HREF=\".+?>(.+?)<\/A/) && ($HREF = $1);     
      (/FONT COLOR=.+?B>(.+?)<\/B/) && ($FONT = $1) || ($FONT = "NA");
          (/center\">(.+?)<\/td/) && ($align = $1);
          (/<\/tr>/ && $FONT eq 'Up') && print "$HREF $FONT $align\n";
' file

This Code fails for above mentioned data sample in post #5
Sponsored Links
Reply

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
how to find out recurrence and print it. pirates.genome Shell Programming and Scripting 2 02-02-2012 09:33 AM
Print a Search Pattern after modification dpooleco Shell Programming and Scripting 5 06-08-2011 07:15 AM
Find and symbolic link modification time earls Shell Programming and Scripting 1 09-27-2010 07:58 AM
ls -e to find out File modification time in secs rahulkav Shell Programming and Scripting 3 09-12-2008 11:04 AM
How to find out who did the modification nick27 UNIX for Dummies Questions & Answers 0 08-19-2005 03:32 PM



All times are GMT -4. The time now is 04:50 AM.