LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-05-2004, 08:01 AM   #1
TheDarktrooper
LQ Newbie
 
Registered: May 2004
Posts: 5

Rep: Reputation: 0
Multiple Field Seperators in Awk...


Ok, how do you do this?
for example, i want to have the field seperators set to " ) ( and space

so you might have:

FS = "/"" || ")" || "(" || " "

which doesn't work (to the best of my knowledge.. which admittedly is quite limited), but how would you set it out so that it actually works?

Thanks
 
Old 05-05-2004, 08:33 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
You can use regular expressions as a field separator.
Within the regular-expression-field-separator, I suppose you can specify some "or"-operator.

Type:
info gawk "Regexp Field Splitting"
for more information.
 
Old 05-05-2004, 09:50 AM   #3
TheDarktrooper
LQ Newbie
 
Registered: May 2004
Posts: 5

Original Poster
Rep: Reputation: 0
could you go into a bit more detail by any chance? im kind of a linux n00b and i can only use it when im at uni (dont have it installed on my own pc.. not enough room on my HD) so if you could explain a bit better i'd appreciate it.
 
Old 05-05-2004, 11:55 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Start your awk script with:
Code:
BEGIN { FS="[/() ]" }
 
Old 05-06-2004, 03:27 AM   #5
TheDarktrooper
LQ Newbie
 
Registered: May 2004
Posts: 5

Original Poster
Rep: Reputation: 0
hmm, ok, so how would that work with "'s?

i know when just setting the FS normall you have to go : FS = "\"" to set a seperator as quotes, but just going \" inside the square brackets causes a parse error...

is there any way to combine the two?
 
Old 05-06-2004, 04:42 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Quote:
[...] but just going \" inside the square brackets causes a parse error...
No. This \" thing works correctly.
Remember to put the script inside single quotes on the command line (or put the script in a separate file).

This works (at least with GNU awk):
Code:
awk 'BEGIN { FS="[/()\" ]" } {print $1 " " $2 " " $3 }' data.txt
 
Old 05-06-2004, 04:50 AM   #7
TheDarktrooper
LQ Newbie
 
Registered: May 2004
Posts: 5

Original Poster
Rep: Reputation: 0
ah awesome thanks alot, i see what i was doing wrong.
 
  


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
quick hand with awk multiple field separators pld Programming 10 05-28-2010 07:51 AM
AWK: print field to end, and character count? ridertech Linux - Newbie 1 05-07-2004 05:07 PM
My field separator changes when using awk Helene Programming 3 05-01-2004 08:10 AM
Two field seperators in awk?? Astro Programming 2 11-09-2003 10:12 AM
storing multiple values within one field in mysql antken Programming 8 12-15-2002 10:08 PM

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

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