Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Have a think of what you are asking here and at what point you are in the code when you ask it.
By the time your awk script has something in $0 it has already performed the split and as you do not set it prior to this it will use the default.
Also, awk can read a file so cat is not required.
Yeah when i add a begin statement and set the field separator to space I get a "FIVE" as a result, when i set the field separator to colon i get
a "4 FIVE".
I am not crystal clear on this but I think that the field separation is a parameter best set before the line iteration, not while. i can do this all with bash - i just am onn a awk kick and want to explore the language. thanks.
FS can be a regular expression: FS=/[ :]/ or FS=/( +)|:/ might be what you want.
<edit>
Or, more generally, FS=/([[:space:]]+)|:/ or FS=/[[:space:]]*[:[:space:]][[:space:]]*/
That last one says "zreo or more white-space characters followed by either a white-space character or a colon, followed be zero of more white-space characters"
</edit>
Last edited by PTrenholme; 10-22-2011 at 04:41 PM.
hmmm ... not quite sure where you were going with this one PT? Neither of your edited versions seem to return any output for the third field.
ahh .. just a did little test ... the issue is that whilst FS is a computed regex it requires quotes (""), although the are turned into slashes (//) at some point.
Any way, even with quotes you are not generating the desired output.
@OP - I believe the best solution is to you use split when you encounter a colon in the line and FS the rest of the time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.