How to Grep for particular word and display..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Grep for particular word and display..
# 1  
Old 09-30-2008
How to Grep for particular word and display..

Hi Guru's.... I've one log file in all my systems which writes the backup information..

I'have written a command like this:

ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}'

We have nearly 50 systems in our landscape, hence when i run this command the $7 would not work since the log file is saving in exactly in all the systems when i check i found the below three formats:

1.) insert into sapqd4.sdbah values ('20080808051812','net','QD4','DB','0','20080808054531','netbackup','netbackup')
2.) new 1: insert into sapqd1.sdbah values ('20080725011009','net','QD1','DB','0','20080725052004','netbackup','netbackup')
3.) new 1: insert into sapr3.sdbah values ('20080920182244','net','DB','0','20080921013618','netbackup')

Hence when i use the $7 the output is not accurate..

Now i would like to wirte a a command which only searches for ( and display the output..

Actual line:
new 1: insert into sapr3.sdbah values ('20080927210501','net','DB','0','20080928084821','netbackup')

Desired output:

('2008/09/27/ 21:05:01 ','net','DB',' 0 ',' 2008/09/28/ 08:48:21 ','netbackup')

The things which shown in read should not dispaly, the only ouput the i need is in black colour.


Any help would be greatfully appreciated..


Thanks in advance..
# 2  
Old 09-30-2008
Code:
ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |
awk '/insert/ { line=$0 }
END {
  sep="";
  n=split (line, f, "'"'"'");
  for (i=1; i<=n; i++)
    if (f[i] !~ /[^0-9]/) {
      if (f[i] > 10000)
        printf "%s%s/%s/%s/ %s:%s:%s", sep, substr(f[i],1,4), substr(f[i],5,2), substr(f[i],7,2),
          substr(f[i],9,2), substr (f[i],11,2), substr (f[i],13,2);
      else
        printf "%s%s", sep, f[i];
      sep=",";
    }
  printf "\n"; }'

Notice how this splits on single quote (obfuscatedly written "'"'"'" because of shell quoting mechanisms) and extracts those values which are all numeric. If this is unsuitable, probably an altogether different strategy is required.
# 3  
Old 09-30-2008
May be this can help you a little bit

bijayant@bijayant~ $ cat testfile
new 1: insert into sapr3.sdbah values ('20080927210501','net','DB','0','20080928084821','netbackup')

bijayant@bijayant ~ $ cat testfile |cut -d "(" -f2 | tr "','" " " | awk '{print $1 " " $4 " " $5}'
20080927210501 0 20080928084821
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep for a word and display last transection?

Hi, When we "grep" for a word in a file, it returns the last lines containing the word that we searched for. Is there a way to display last line to grep. Thanks Ex log. Ex. logname.log 2015-07-29 06:43:07.023|BETA |2015-07-29... (5 Replies)
Discussion started by: ooilinlove
5 Replies

2. Shell Programming and Scripting

Grep word after last occurance of string and display next few lines

Hi, I wanted to grep string "ERROR" and "WORNING" after last occurrence of String "Starting" only and wanted to display two lines after searched ERROR and WORNING string and one line before. I have following cronjob log file "errorlog" file and I have written the code for same in Unix as below... (17 Replies)
Discussion started by: nes
17 Replies

3. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

4. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

5. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. Shell Programming and Scripting

Finding a "word" through grep but display line above?

Hi guys. I am trying to perform a search using grep. I get my grep to work, but need to "awk" a Process Number that is 2 lines above... Example: I run a query on my TSM server for Processes that are "Waiting" for something...it returns this: Process Number: 32,881 Process... (14 Replies)
Discussion started by: Stephan
14 Replies

7. UNIX for Dummies Questions & Answers

how to grep the word and display only the second word from it

hi, consider the below line in a text file, 'Y',getdate(),'N','V',NULL ..... 'N',getdate(),'Y','D',NULL ..... 'Y','N','Y',getdate(),'Y','D',NULL .... as u see above, i want only the second word after the getdate() word... getdate() will not come 2nd word alwys it may be any position but i... (11 Replies)
Discussion started by: prsam
11 Replies

8. Shell Programming and Scripting

grep display word only

Folks, is it possible to display only words with grep (or any built-in ultility)? I have more than 1 pattern to search, say apple & orange The text goes like this: So I need to display all the words starting with apple or orange The output should be: Any idea? (7 Replies)
Discussion started by: bsddaemon
7 Replies

9. UNIX for Dummies Questions & Answers

how to grep for a word and display only the word

Hi, When we "grep" for a word in a file, it returns the lines containing the word that we searched for. Is there a way to display only the words and not the entire line containing them. Thanks Ananth (6 Replies)
Discussion started by: ananthmm
6 Replies

10. UNIX for Dummies Questions & Answers

grep a word and display its column

Hi, I need idea about this, say I have this line: 05 21 * * 0,6 /user/clean.desktop.sh > /tmp/desktop_rpt 2>&1 I would need to grep the word desktop and display the /user/clean.desktop.sh and not the whole line. And if I have some more lines say, 05 21 * * 0,6 /user/clean.desktop.sh >... (1 Reply)
Discussion started by: Orbix
1 Replies
Login or Register to Ask a Question