Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 03-04-2012, 08:45 PM   #1
Registered: Apr 2009
Posts: 64

Rep: Reputation: 15
Parsing help. Using grep and awk for the creation of a configuration file.


I'm trying to parse a file right now. It's in an HTML format. I've managed to use grep and awk to get snippets of information out of this file, and that's fine. But now I need to organise the information into a usable format. Let me show you what I'm doing now, and what I want.

<param name="4" value="76">
So now to get the "4" out, I do this:
cat testfile|awk -Fparam\ name=\" '{print $2}' | awk -F\" '{print $1}'
Now I want to output the result into a file.
echo `cat testfile|awk -Fparam\ name=\" '{print $2}' | awk -F\" '{print $1}'` > file
And now the second part. The value area. Uh oh, what do I do now?

Yeah, there's where I'm stuck, since I have many more of these, the result is more than one line. If there was only one line I could do this:
echo `cat testfile|awk -Fparam\ name=\" '{print $2}' | awk -F\" '{print $1}'` `cat testfile|awk -Fvalue=\" '{print $2}' | awk -F\" '{print $1}'`
So I need to find a way to parse line by line. Parse one line's "param name" option, then the value option and output that to a file, insert a newline, then repeat.

Would appreciate if someone can help. I'm just not sure what to do.

Thanks in advance,
Old 03-04-2012, 10:17 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
awk -F\" '
    print $2 " " $4
' input.txt
1 members found this post helpful.
Old 03-05-2012, 03:19 AM   #3
Registered: Apr 2009
Posts: 64

Original Poster
Rep: Reputation: 15
Thanks, that did the trick.


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
parsing a text file - to awk or not to awk ? rollyah Programming 9 08-18-2011 03:20 PM
[Grep,Awk,Sed]Parsing text between XML tags. ////// Programming 5 07-26-2011 12:54 PM
[SOLVED] parsing out squid access log with awk and grep druisgod Programming 8 04-26-2011 11:40 AM
Parsing log file with awk sebelk Programming 1 08-31-2009 09:47 AM
awk question - parsing xml file epoo Programming 7 01-24-2007 03:13 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:17 AM.

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