LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 10: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, 11:56 PM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,549
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Sounds like homework to me!

Show us what you have tried to date.
 
Old 08-08-2008, 11: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, 10: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


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


All times are GMT -5. The time now is 04:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration