Fedora Linux Support Community & Resources Center
  #1  
Old 13th December 2009, 11:00 PM
NewLinuxUser Offline
Registered User
 
Join Date: Dec 2009
Posts: 10
windows_vistafirefox
awk, script, next

Here is the situation I am having now, I can't get the next to work. Perhaps I don't understand the context in which to use it. I have 3 commands in my script file:

one is: /title/ {print $1}
second is: /number/ {print $1 "makes" $3}
third is: BEGIN {print "\033[4mCol1 \tCol2\033[0m"}
{if ( x == "y" ) print $2, $3}

It will print it all out but no matter where I put the next, either after one, two or three, it still prints it out in the same way:

Col1 Col2
Dave makes 10.00
Johnson 30
Janeway 30
Bud
Mark

I don't want it to come out like that. I want it to come out like this:

Bud
Mark

Col1 Col2
Johnson 30
Janeway 30

Dave makes 10.00

It seems that the file it is reading from--Dave is at the top of the list; Then Johnson and Janeway; and finally Bud and Mark are toward the bottom of the list. So, it is processing it according to how the text file is listing these lines. Can that be changed?
Reply With Quote
  #2  
Old 13th December 2009, 11:15 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,109
linuxfedorafirefox
It can work but only if the entire file is loaded into arrays, each with its target.
The array with only one field are printed first.
The array with two fields are then printed.

How you determine the difference between Dave and Johnson/Janeway records
is still up in the air.

The only other way I can think of is to process the records in a pipeline, the first
defines the categories of records (one field, two fields, and however you identify
Dave) and outputs the record prefixed by the category, and passes the output to
sort, which reorders the file, and passes the result to a third filter that takes the
ordered records and outputs the final report using the category index to select
the line format.
Reply With Quote
  #3  
Old 14th December 2009, 02:40 AM
NewLinuxUser Offline
Registered User
 
Join Date: Dec 2009
Posts: 10
windows_vistafirefox
That sounds a little over my head. I am very new to this. I haven't even worked with arrays before. Isn't using "next" suppose to be for the purpose of processing a new command line?

---------- Post added at 08:40 PM CST ---------- Previous post was at 05:44 PM CST ----------

I got everything figured out..didn't need the "next" statement at all. Set it up in a script file and entered the commands on individual lines and works just fine!
Reply With Quote
Reply

Tags
awk, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 10:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 09:30 PM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM
Script - Converting a dos bach script to linux jond Using Fedora 12 2nd May 2005 04:45 PM


Current GMT-time: 11:07 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat