Find and print Modification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and print Modification
# 1  
Old 02-09-2012
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 05:34 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-09-2012
Assuming, the format is consistent across!
Code:
awk -F"[><]" '/HREF/{h=$(NF-4)}/Down/{getline;getline; print h,"Down",$(NF-2)}' infile

--ahamed
# 3  
Old 02-09-2012
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

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 02-09-2012
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

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-09-2012
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 08:31 AM..
# 6  
Old 02-09-2012
(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 }
# 7  
Old 02-09-2012
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk, find and print

Ubuntu, Bash 4.3.48 Hi, I have this input file with many columns separated with ":" ARC=121:ERF=12244:IDE=2334:ADA=34 .... ERF=124:ARC=123:IDE=2344:ADA=54 .... ERF=16254:IDE=2434:ADA=78:ARC=134 .... and I want this: ARC=121:IDE=2334 ARC=123:IDE=2344 ARC=134:IDE=2434 I need to... (5 Replies)
Discussion started by: echo manolis
5 Replies

2. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

3. Shell Programming and Scripting

How to list the files based on the modification time using the find command?

Hi All, I need to list the files based modification time of the files from a directory, I cannot use "ls -t" as there are lot of files, which "ls" command cannot handle. New files will land there daily. So iam looking for an alternative through "find"command. All suggestions are welcomed. ... (6 Replies)
Discussion started by: Kesavan
6 Replies

4. Shell Programming and Scripting

how to find out recurrence and print it.

Hi all, I have a file having data like this: rs4332761 15XB rs4332761 unk rs4571228 15XB rs457263 5XB rs4606515 10XA rs4606515 10XB rs4606515 15XB I want output like this: rs4332761 15XB,unk rs4571228 15XB rs457263 5XB rs4606515 10XA,10XB,15XB I... (2 Replies)
Discussion started by: pirates.genome
2 Replies

5. Shell Programming and Scripting

Find x and print its record

Hi all, I have a file containing two fields with 154 rows/records/lines (forgive me, my UNIX terminology is not quite up to par yet). I am trying to read from this list, find a value (lets say 0), then print the record/line/row that value falls on (In this case it would be record/line/row #27)?... (5 Replies)
Discussion started by: StudentServitor
5 Replies

6. Shell Programming and Scripting

Print a Search Pattern after modification

Using either vim or awk or sed If I wish to to search for an unknown pattern - lets say 1B2495 or 1Q2345 so Search pattern : 1 and replace the 1 with 2 to print out : 2B2495 or 2Q2345 what are the possible commands. Struggling here - help would be appreciated. (5 Replies)
Discussion started by: dpooleco
5 Replies

7. Shell Programming and Scripting

Find and symbolic link modification time

Hi, I have a directory made up of many symbolic links to folders multiple file systems. I want to return folders modified within the last 50 days, but find is using the link time rather than the target time. find . -type d -mtime -50 Is there a way to either: a) Make a symbolic link... (1 Reply)
Discussion started by: earls
1 Replies

8. Shell Programming and Scripting

ls -e to find out File modification time in secs

Hi All, I would like to know the file modification time till seconds in Unix. So I tried ls -e and it worked fine. This Solaris 5.10 -rw-rw-r-- 1 test admin 22 Sep 12 11:01:37 2008 test_message But I am not able to run the same command in SOlaris 5.6 and also in AIX/HP Is there... (3 Replies)
Discussion started by: rahulkav
3 Replies

9. UNIX for Dummies Questions & Answers

How to find out who did the modification

Hi guys, In the UNIX work environment we have access other peoples directory and sometimes we have full access to other people's files. How can we find out , other than modification time that WHO did modification on any file ? I know we can change the access of any file by chmod but... (0 Replies)
Discussion started by: nick27
0 Replies

10. UNIX for Dummies Questions & Answers

How to Find /replace and print?

Hi, I have one txt file, and I want replace 2 diffrent texts with somther text and the same time, I want to send that to print.. something like sed -e 's/Times-Roman/Helvetica/'|sed -e 's/Times/Helvetica/' oldfile > newfile < lp is this will workout? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question