How to extract strings from full path when full path is not fixed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract strings from full path when full path is not fixed
# 1  
Old 10-07-2010
How to extract strings from full path when full path is not fixed

Code:
/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.
/Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.
/Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.
/Path/snowbird15/nrfraveComp10_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball6/nrfraveComp10_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball9/nrfraveComp13_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball15/nrfraveComp14_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball14/nrfraveComp22_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball10/nrfraveComp23_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball11/nrfraveComp09_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/thunderball13/nrfraveComp01_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/nrfraveComp01_SocketServerLog20100920.log.gz:09/20/2010 06:14:51 INFO [UNKNOWN] INFO Message.
/Path/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.

Note: Error Message contains Errors. INFO message contains information messages. so those are not fixed strings.


Here as $1 is having the full path...as my script takes parameter as input path. It will consists of three patterns
Code:
/Path/thunderball*/nrfraveComp10_SocketServerLog20100920.log.gz:09/20/2010
/Path/snowbird*/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.
/Path/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR [UNKNOWN] Error Message.

Currently I have checked for the below command but problem here is in my input path i have /nrf/snowbird* or /nrf/thunderball* so i am making that as blank when i find /nrf in path. but it doesnot provide flexibility for the input path parameter that i am passing to script.
Code:
cat errors.txt | awk -F':|] ' '/ERROR|INFO/{sub(".*/nrf/","",$1);OFS=",";sub("/",",",$1);a[$1 OFS $NF]++}END{for(i in a)print i,a[i]}' | sort -k1,3 > report.csv

Above command displays required output for me like
Code:
ServerName,Filename,Error String,Count of String
snowbird9,nrfCompMgrRave1230100920.log.gz,Error Message.,1
thunderball6,nrfraveComp10_SocketServerLog20100920.log.gz,INFO Message.,1

But it is having limitation that it will always look for fixed pattern in $1(i.e.,/nrf). So I need to check in $1 if thunderball* or snowbird* is exists then print servername in report and if it is not exits then column for Servername should be blank.

does anybody have any idea how to implement it...

Thanks in advance !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

2. Programming

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (1 Reply)
Discussion started by: KidD312
1 Replies

3. UNIX for Advanced & Expert Users

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (0 Replies)
Discussion started by: KidD312
0 Replies

4. Shell Programming and Scripting

$0 doesn't have full directory path

I'm running AIX unix korn shell. If I echo $0, I only get the filename, it does not have the directory name also. So when I do: `dirname $0` it returns a . (meaning current directory). How get $0 to return the full path/filename? Do I need something in my .profile? Thank you. (8 Replies)
Discussion started by: sboxtops
8 Replies

5. Shell Programming and Scripting

Need to extract a folder from a full path

Hi everyone, I have different folders which looks like this: /mnt/ecrm/master/ecrm/templates/brochure/de_DE/zeitlos.ott /mnt/ecrm/master/ecrm/templates/mail/en_US/default.html /templates/header_and_footer/en_US/default.txt I want to get the bold text only in a variable. I already have a... (3 Replies)
Discussion started by: evilass
3 Replies

6. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

7. UNIX for Dummies Questions & Answers

Listing files with full path

Hi, I need to store all the files in a directory to a text file with its full path. The example below can explain: ./File1.txt ./File2.txt ./Folder1/File11.txt ./Folder1/File12.txt ./Folder1/Folder11/File111.txt ./Folder2/file21.txt : : The ls -R1 command won't give the result as... (5 Replies)
Discussion started by: r_sethu
5 Replies

8. Shell Programming and Scripting

List files with full path

Hi all, How to save file full name to a file. I tried the following but don't know to include path name. $ ls -l | awk '{print $9}' > outputfile.dat $ cat outputfile.dat fifth.txt first.txt fourth.txt second.txt third.txt My wanted result is ie: ... (3 Replies)
Discussion started by: mr_bold
3 Replies

9. Shell Programming and Scripting

getting full path from relative path

given a relative path, how do i convert it into a full one. i.e. if i am in /home/polypus and i am given foo/bar then to get a full path i can just concatinate it with pwd, but what if i am given "../mama" how do i programmatically convert: /home/polypus and ../mama into ... (4 Replies)
Discussion started by: polypus
4 Replies

10. UNIX for Dummies Questions & Answers

extract only file name from full path file name

What is the smartest way to just extract file name from a full path name. e.g. if I have /usr/sanjay/bin/file_name.c I want only file_name.c Sanjay (2 Replies)
Discussion started by: sanjay92
2 Replies
Login or Register to Ask a Question