Shell Script Extraction

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Infrastructure Monitoring Shell Script Extraction
# 1  
Old 06-15-2010
Shell Script Extraction

Hello Users,

I am new to unix. I have a requirement to extract the string in the folder with files names XXXX.sev.xxxxx.lookup (There are some more files which I am not interested in like xxxxx.include.xxx.lookup).

1) I am looking for the file with the name "sev" ending with "lookup"

For example there will be a file with juniper-MIB.sev.snmptrap.lookup

2) In that file I want to extract a string starting with "SNMP". For example the above file would contain the following information
Code:
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspUp","1","2","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspDown","3","1","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspChange","2","13","1800"},

The output should be SNMPTRAP-juniper-MPLS-MIB-mplsLspUp . There should not { " etc.

3) The output should be sent to a file.

Can some please help me how I can achieve using shell script.

Your help is highly appreciated.

Thanks.
Regards,
RaviShankar.

Last edited by Scott; 06-15-2010 at 11:56 AM.. Reason: Please use code tags
# 2  
Old 06-15-2010
Welcome to the forum.

Please try this:
Code:
for file in *.sev.*.lookup
do
   awk -F \" '/^\{"SNMPTRAP/{print $2}' $file
done

even try this one liner,
Code:
awk -F \" '/^\{"SNMPTRAP/{print $2}' *.sev.*.lookup

# 3  
Old 06-15-2010
Shell Script Extraction

Dear Anchar,

Thanks for your reply.

When I run that script, I do not see any output on the terminal screen.
The script terminates without any error. But I am not able to see the output.

Thanks.
Regards,
RaviShankar.
# 4  
Old 06-15-2010
which OS you are using?
If solaris, try nawk.


Are you sure that any of the file contains that pattern?

also try this:

Code:
awk -F \" '/^{"SNMPTRAP/{print $2}' *.sev.*.lookup

Both are working for me on linux.
# 5  
Old 06-15-2010
Shell Script Extraction

Dear Anchal,

I am also using RHEL version 5.

Below is the file name and its content
File name :
juniper-MPLS-MIB.sev.snmptrap.lookup

Code:
 
table juniper-MPLS-MIB_sev =
{
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspUp","1","2","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspDown","3","1","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspChange","2","13","1800"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspPathDown","3","1","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspPathUp","1","2","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoUp","1","2","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoDown","3","1","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoChange","2","13","1800"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathDown","3","1","0"},
    {"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathUp","1","2","0"}
}
default = {"Unknown","Unknown","Unknown"}

But for some reason it is not displaying the output

Thanks.

Last edited by Scott; 06-15-2010 at 11:57 AM.. Reason: Code tags, please...
# 6  
Old 06-15-2010
strange!!
What is the source of the file? did you transfer the file from dos/windows?


re-create the file with the same contents just to test.
if you having dos2unix utility, try that.

what is what I tried with your file,
Code:
$ cat juniper-MPLS-MIB.sev.snmptrap.lookup 
table juniper-MPLS-MIB_sev =
{
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspUp","1","2","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspDown","3","1","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspChange","2","13","1800"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspPathDown","3","1","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspPathUp","1","2","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoUp","1","2","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoDown","3","1","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoChange","2","13","1800"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathDown","3","1","0"},
{"SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathUp","1","2","0"}
}
default = {"Unknown","Unknown","Unknown"}
 
$ awk -F \" '/^\{"SNMPTRAP/{print $2}' *.sev.*.lookup
SNMPTRAP-juniper-MPLS-MIB-mplsLspUp
SNMPTRAP-juniper-MPLS-MIB-mplsLspDown
SNMPTRAP-juniper-MPLS-MIB-mplsLspChange
SNMPTRAP-juniper-MPLS-MIB-mplsLspPathDown
SNMPTRAP-juniper-MPLS-MIB-mplsLspPathUp
SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoUp
SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoDown
SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoChange
SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathDown
SNMPTRAP-juniper-MPLS-MIB-mplsLspInfoPathUp
$

# 7  
Old 06-15-2010
A sed version:

Code:
 
sed -n '/SNMP/p' input_file | sed 's/{"\(.*[a-zA-Z]\).*/\1/g' > outpt_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script for extraction of pattern

Anyone can help here, with a script to extract the highlighted details from this two blocks?Actually there are milions of block, this is a sample? dn: EpsStaInfId=EpsStaInf,serv=EPS,mscId=aaaaaa001aaaaaaaa629100100138702,ou=multiSCs,dc=mtncg structuralObjectClass: EpsStaticInf objectClass:... (19 Replies)
Discussion started by: gillesi
19 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

Correct shell script to Call One shell script from another shell script

Hi All, I have new for shell scripting. Problem : I have one scrip at serv1 and path of server is /apps/dev/provimage/scripts and script name:extract_ancillary.bat. I need to call this script at server2(my working server) and execute at server2 . Please let me know how to build the... (5 Replies)
Discussion started by: Vineeta Nigam
5 Replies

6. Shell Programming and Scripting

Pattern extraction and usage by shell script

Suppose im in a directory A. which has sub-directories x/y/z m/n/p etc. Iam only considered with those which have a file netl.oa at the lowermost level. So i used the find command which gives me a list in the form ./abc/def/ghi/jkl/netl.oa and so on Now i want the names abc def jkl and ghi. My... (3 Replies)
Discussion started by: sid.verycool
3 Replies

7. Shell Programming and Scripting

Date and time range extraction via Awk or analysis script?

Hello does anyone know of an awk that will extract log file entries between a specific date and time range, eg: awk '/15\/Dec\/2010:16:10:00/, /15\/Dec\/2010:16:15:00/' access_log but one that works? Or a free command line log file analysis tool/script? I'd like to be able to view... (2 Replies)
Discussion started by: competitions
2 Replies

8. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

9. Shell Programming and Scripting

Shell script for text extraction from a file

Hi All, I am new to Shell Scripting. I have a file consisting of XML messages.Each message is associated with a timestamp value(it is not a xml field).I need to extract\copy all messages in a particular time interval and put in another new file using Shell Scripting. My XML looks like... (3 Replies)
Discussion started by: vignesh53
3 Replies

10. Shell Programming and Scripting

help with data extraction script

Hello all, Iam newbie here and to unix programming. I have the following text file. A:Woshington,B:London,C:Paris,D:Manchester,C:Lisbon,E:Cape town. Now I would like extract this and store in database. here is the script I have tried but it did work. CITY1:`echo "$text" | grep "A:"... (11 Replies)
Discussion started by: mam
11 Replies
Login or Register to Ask a Question