LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2010, 08:40 AM   #1
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Rep: Reputation: 15
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 -
 
Old 02-09-2010, 08:51 AM   #2
boyd98
Member
 
Registered: Oct 2003
Posts: 156

Original Poster
Rep: Reputation: 15
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
 
Old 02-09-2010, 11:17 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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]$
 
Old 02-12-2010, 01:57 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

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

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace a field for a whole line in the same file, with awk. amwink Programming 12 11-13-2009 06:51 AM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 09:43 AM
checking for intltool >= 0.35.0... awk: cmd. line:1: fatal: cannot open file `./intlt chytraeus Linux - Software 2 12-25-2008 05:08 AM
bash/sed/awk fill each line in text file with space to fixed length khairil Programming 11 01-09-2008 05:28 AM
[SOLVED] use awk &/or sed to read file 1 line 1 & file 2 line 1 gr8scot Linux - General 6 07-12-2007 08:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration