Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-08-2003, 04:50 PM   #1
Registered: Jan 2003
Location: Ballston Lake, NY
Distribution: Slackware, Debian
Posts: 660

Rep: Reputation: 30
Two field seperators in awk??

Need to parse a file with two different field seperators. Here's an example line form the file...

FOSS:05-23-00:Paper,9.95:Game,45.99:Hub,39.95:Patch Cable,29.95

format is name:date:item,price...etc

there can be any # of item,price's at the end

in the beginning of the awk script the field seperator needs to be set to ":" for the main seperation of the fields.... but how can I extract the items and prices based on the "," field seperator??
Old 11-08-2003, 07:12 PM   #2
Registered: Oct 2003
Posts: 66

Rep: Reputation: 15
Unless I misunderstand what you want:

Extract the field and treat the items separately:
awk -F: '{print $3}' file1 | awk -F, '{print $1, $2}'
Paper 9.95
Old 11-09-2003, 11:12 AM   #3
Registered: Jan 2003
Location: Ballston Lake, NY
Distribution: Slackware, Debian
Posts: 660

Original Poster
Rep: Reputation: 30
Good idea, but I think I figured out what needed to be done.... did a little reading and found the split operator...

for (i=3;i<=NF;i++)
Set i=3 cause thats always the first item,price...
<= to the # of fields so it can get the last value
split $i using "," and add it up to get my total.

Arr[2] being the price and Arr[1] being the item...



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 08:51 AM
TOS field value lucs Slackware 1 03-31-2005 11:55 AM
AWK: print field to end, and character count? ridertech Linux - Newbie 1 05-07-2004 06:07 PM
Multiple Field Seperators in Awk... TheDarktrooper Programming 6 05-06-2004 05:50 AM
My field separator changes when using awk Helene Programming 3 05-01-2004 09:10 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration