extract using sed/awk - need help? Please!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract using sed/awk - need help? Please!!
# 1  
Old 10-08-2007
extract using sed/awk - need help? Please!!

Need help..not sure how to use with awk or sed
I want to take data from the notification.$$ file and assign the data to variable "group". Not sure how to do it.

The data I want to extract from the notification.$$ is on the first line of the file ..right after the (notice):
NetWorker savegroup: (notice) EGL completed,


1 # This script sends email that save group completed.
2 #!/bin/sh
3 group=" "
4 dat=`date +"%c"`
5 log='/nsr/logs/test_savegrp.log'
6 echo "\n -- BUR Legato $dat Test Save Group Notification -- \n" >> $log
7 tee notification.$$ >> $log
8 group=`grep -l notice
9 echo " -- $dat end of $group Savegroup Message --\n" >> $log
10 awk "
11 /usr/ucb/mail -s "$dat $group-BUR Networker Savegroup Completion Report" xxx.email < notification.$$ >>
$log 2>&1
~
~
# 2  
Old 10-08-2007
I figured this so far...

So how do I assign the print $4 to another variable that I can save within the script.



egrep notice 20071008_1105_savegroup.txt | awk '{print $4}'; grp="$4"; echo $grp
EGL-Rerun
# 3  
Old 10-08-2007
do this

grp=`grep notice 20071008_1105_savegroup.txt | awk '{print $4}'`
or
grp =`grep notice 20071008_1105_savegroup.txt | cut -d'delimeter' -f4`
or
grp =`awk '/notice/{print $4}'`

cheers,
Devaraj Takhellambam
# 4  
Old 10-08-2007
But It still will not pass my $4 to where I need to print it. How can I assign that $4 to a variable to save.


1 # This script sends email that save group completed.
2 #!/bin/sh
3 dat=`date +"%c"`
4 log='/nsr/logs/savegrp.log'
5 echo "\n -- $4 BUR Legato $dat Save Group Notification -- \n" >> $log
6 tee -a notification.$$ >> $log
7 grep notice notification.$$
8 awk '{print $4}'
9 grp=`awk '{print $4}`
10 echo " -- end of $grp Savegroup Message --\n" >>$log
11 sudo /usr/ucb/mail -s "$dat $4 Networker Savegroup Completion Report" mailxxx.com < notification.$$ >> $
log 2>&1
# 5  
Old 10-08-2007
1 # This script sends email that save group completed.
2 #!/bin/sh
3 dat=`date +"%c"`
4 log='/nsr/logs/savegrp.log'
5 echo "\n -- $4 BUR Legato $dat Save Group Notification -- \n" >> $log
6 tee -a notification.$$ >> $log
7 grep notice notification.$$
8 awk '/notice/{print $4}' notification.$$
9 grp =`awk '/notice/{print $4}' notification.$$ `
10 echo " -- end of $grp Savegroup Message --\n" >>$log
11 sudo /usr/ucb/mail -s "$dat $grp Networker Savegroup Completion Report" mailxxx.com < notification.$$ >> $
log 2>&1



cheers,
Devaraj Takhellambam
# 6  
Old 10-08-2007
Thank-you so much for your help. That worked. Smilie
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/sed command to extract the string between 2 patterns but having some particular value

Hi - i have one file with content as below. ***** BEGIN 123 ***** BASH is awesome ***** END ***** ***** BEGIN 365 ***** KSH is awesome ***** END ***** ***** BEGIN 157 ***** KSH is awesome ***** END ***** ***** BEGIN 7123 ***** C is awesome ***** END ***** I am trying to find all... (4 Replies)
Discussion started by: reldb
4 Replies

2. Shell Programming and Scripting

sed / awk / grep to extract information from log

Hi all, I have a query that runs that outputs data in the following format - 01/09/12 11:43:40,ADMIN,4,77,Application Group Load: Name(TESTED) LoadId(5137-1-0-1XX-15343-15343) File(/dir/dir/File.T03.CI2.RYR.2012009.11433350806.ARD) InputSize(5344) OutputSize(1359) Rows(2) Time(1.9960)... (8 Replies)
Discussion started by: jeffs42885
8 Replies

3. Shell Programming and Scripting

Awk/sed HTML extract

I'm extracting text between table tags in HTML <th><a href="/wiki/Buick_LeSabre" title="Buick LeSabre">Buick LeSabre</a></th> using this: awk -F "</*th>" '/<\/*th>/ {print $2}' auto2 > auto3 then this (text between a href): sed -e 's/\(<*>\)//g' auto3 > auto4 How to shorten this into one... (8 Replies)
Discussion started by: p1ne
8 Replies

4. Shell Programming and Scripting

Extract info and do algebra on it by sed or awk

Hello everyone, I need to extract some information from a csv file and further need to do some algebraic calculations on those information and then to throw the result in a new file. Here is a sample from my data.csv file; Col1,Col2,Col3,Col4,Col5,Col6,Col7... (19 Replies)
Discussion started by: hayreter
19 Replies

5. Shell Programming and Scripting

Extract a substring using SED/AWK

Hi All, I have a log file in which name and version of applications are coming in the following format name It may look like following, based on the name of the application and version: XYZ OR xyz OR XyZ OR xyz I want to separate out the name and version and store them into variables.... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

6. Shell Programming and Scripting

Extract word from text (sed,awk, etc...)

Hello, I need some help extracting the number after the RBA e.g 15911688 from the below block of text (e.g: grep RBA |sed .......). The code should be valid for blocks if text generated at different times as well and not for the below text only. ... (2 Replies)
Discussion started by: drbiloukos
2 Replies

7. Shell Programming and Scripting

Using SED/AWK to extract xml at end of file

Hello everyone, Firstly i do not require alot of help.. i am right at the end of finishing my scipt but cannot find a solution to the last part. What i need to do is, prompt the user for a file to work with, which i have done. promt the user for an output file - which is done. #!/bin/bash... (14 Replies)
Discussion started by: hugh86
14 Replies

8. UNIX for Dummies Questions & Answers

Using awk/sed to extract text between Strings

Dear Unix Gurus, I've got a data file with a few hundred lines (see truncated sample)... BEGIN_SCAN1 TASK_NAME=LA48 PDD Profiles PROGRAM=ArrayScan 1.00 21.220E+00 2.00 21.280E+00 END_DATA END_SCAN1 BEGIN_SCAN2 TASK_NAME=LA48 PDD Profiles 194.00 2.1870E+00 ... (5 Replies)
Discussion started by: tintin72
5 Replies

9. Shell Programming and Scripting

sed or awk to extract data from Xml file

Hi, I want to get data from Xml file by using sed or awk command. I want to get the following result : mon titre 1;Createur1;Dossier1 mon titre 1;Createur1;Dossier1 and save it in cvs file (fichier.cvs). FROM this Xml file (test.xml): <playlist version="1"> <trackList> <track>... (1 Reply)
Discussion started by: yeclota
1 Replies

10. Shell Programming and Scripting

Extract some characters with SED or AWK

Hi, I have the following example string: today_is_a_good_day.txt The character "_" inside the string can sometimes be more or less. The solution for every string equal the count of "_" should be alway the rest after the last underline character. Result: day.txt I want to use awk... (5 Replies)
Discussion started by: climber
5 Replies
Login or Register to Ask a Question