LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-07-2008, 09:52 PM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
want awk programmers help...


I hv a data file like this...

id1 id2 number amount
abc 111 35 25.00
abc 111 24 55.00
abc 222 35 65.00
abc 222 58 68.00
def 333 69 58.00
def 333 68 98.00
def 444 88 58.00
def 555 68 68.00

i want the output like this...

name : abc name2 : 111
---------------------------
35 25.00
24 55.00
---------------------------
name2 : 222
---------------------------
35 65.00
58 68.00
---------------------------
name : def name2 : 333
---------------------------
69 58.00
68 98.00
---------------------------
name2 : 444
---------------------------
88 58.00
---------------------------
name2 : 555
---------------------------
68 68.00
---------------------------

i could use while loop for upto id1 but unable to create an inner loop to break id2

Kindly help me...
 
Old 08-07-2008, 10:56 PM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Sounds like homework to me!

Show us what you have tried to date.
 
Old 08-08-2008, 10:46 PM   #3
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
some lines from coding...
{
while($1!=prev){
print""
printf"Name:%s\n",$1
prev=$1
}
print $0
}

like above

with this i could break whenever the value of first field changes
but i dont know how to break whenever the value of the second field
changes...

and one more problem in the above code is that... it is not writing the
very first value of the first field.... i mean to say that the value abc
is not appearing...but the next def and so on can be seen. where I am going
wrong.. Kindly help me.
 
Old 08-16-2008, 09:00 PM   #4
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
hey i got the solution.....!!!

I replaced the while condition by while ($1!=prev1 || $2!=prev2)...it worked well...

say cheers to me...!!!
 
  


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
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 06:23 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 05:39 PM
Question for programmers/occasional programmers Robert Diggs Programming 9 12-23-2006 07:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:14 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