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


Login or Register for Dates, Times and to Reply

 
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  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #149
Difficulty: Easy
In a 1999, Dennis Ritchie stated that Linux and the BSD operating systems were a continuation of the basis of the Unix design approach and were Unix derivatives.
True or False?

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. Shell Programming and Scripting

how to get the scripts full dir path

lyang0@lyang0-OptiPlex-755:~$ ./test.sh . lyang0@lyang0-OptiPlex-755:~$ cat test.sh #!/bin/bash echo `dirname $0` lyang0@lyang0-OptiPlex-755:~$ pwd /home/lyang0 it doesn't get "/home/lyang0" and only when run /home/lyang0/test.sh it will get, but how can I do, then it can get the real... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

3. 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

4. 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

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

Alias a full path in ksh

Hi again, Maybe a stupid question but I don't know how to solve it.. I want to alias a full_PATH_command.. I mean: /usr/bin/df -Ik TO sudo /usr/bin/df I used alias df='sudo df' but the command run is /usr/bin/df.. Any idea on how to make this alias? Thanks (2 Replies)
Discussion started by: iga3725
2 Replies

7. 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

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

Featured Tech Videos