LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can someone help me awk this line out of a file - (https://www.linuxquestions.org/questions/programming-9/can-someone-help-me-awk-this-line-out-of-a-file-788004/)

boyd98 02-09-2010 08:40 AM

Can someone help me awk this line out of a file -
 
buried within this meta file i have, is another file name. I need to pull the file name out:

<?xml version="1.0"?>ne]# cat example.meta
<Meta>
<FileModTime>1244613601</FileModTime>
<FileSize>3862203</FileSize>
<FileSource>file:///home/log/boyd/archive/boyd.log_2009-06-10T02:00:01.log</FileSource>
</Meta>

I have a ton of these meta files and if they exist i need to pull out the log file:
"/home/log/boyd/archive/boyd.log_2009-06-10T02:00:01.log"

and then delete that log file from another directory -

I think i can script the rest, i just can't figure out how to just pull the log file name out of the meta file

I'm just not very strong with awk, I assume there's a way to do it -


Thx in advance for any tips -

boyd98 02-09-2010 08:51 AM

I just came up with this command, but it seems to work, not sure its the most efficient but it works


cat 000-2009-06-10T02:02:11-0-r_boyd.meta |grep archive |awk -F"/" '{ print $8}'|awk -F"<" '{ print $1}'


Let me know if you see anything wrong with passing multiple awk commands

pixellany 02-09-2010 11:17 AM

I put your test into a file named "fil":

Code:

[mherring@mystical play]$ awk -F"/" '{print $8}' fil
boyd.log_2009-06-10T02:00:01.log<

This is printing the filename (+ the "<"), but you said you wanted the whole path.

This works:
Code:

[mherring@mystical play]$ sed -n '/archive/{s/<[^>]*>//g;s/file:\/\///p}' fil
/home/log/boyd/archive/boyd.log_2009-06-10T02:00:01.log
[mherring@mystical play]$


grail 02-12-2010 01:57 AM

If you are happy to change the delimeters this can be made a little shorter:

sed -n '/archive/{s|.*file://\(.*\)<.*|\1|p}'


All times are GMT -5. The time now is 05:51 PM.