LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-26-2007, 07:52 PM   #1
tungaw2001
Member
 
Registered: Aug 2003
Posts: 45

Rep: Reputation: 15
Parsing using awk


Hi all,

I want to parse this file using awk script.....

( 0 , 0 ) =>heading1
( 0 , 1 ) =>value1.1a
( 0 , 2 ) =>value2.1a
( 1 , 0 ) =>heading2
( 1 , 1 ) =>value1.1b
( 1 , 2 ) =>value2.1b
( 2 , 0 ) =>heading3
( 2 , 1 ) =>value1.1c
( 2 , 2 ) =>value2.1c
( 3 , 0 ) =>heading4
( 3 , 1 ) =>value1.1d
( 3 , 2 ) =>value2.1 d

i want to have this kind of output.

first file

heading1=value1.1a
heading2=value1.1b
heading3=value1.1c
heading4=value1.1d

second file
heading1=value2.1a
heading2=value2.1b
heading3=value2.1c
heading4=value2.1d
 
Old 03-27-2007, 02:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
to mandate a certain tool to use, and provide output which seems contrived and arbitrarily complicated suggests that this is homework to me. we are not here to do your work for you.
 
Old 03-27-2007, 05:45 AM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Code:
awk -F"=>" '{ if( $0 ~ "heading" ) { title=$2"=" } else { if ( $0 ~ "value1" ) { print title$2 > "thefirstfile" } else { print title$2 > "thesecondfile" } } }' inputfilename
sorry if this is a homework question!
 
  


Reply



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
[Grep,Awk,Sed]Parsing text between XML tags. ////// Programming 5 07-26-2011 11:54 AM
awk question - parsing xml file epoo Programming 7 01-24-2007 02:13 PM
Sed or Awk question, looking for parsing help rwartell Linux - Software 2 05-17-2006 11:59 PM
Sed or Awk question, looking for parsing help rwartell Programming 1 05-17-2006 04:42 PM

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

All times are GMT -5. The time now is 07:29 PM.

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