LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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-01-2014, 10:24 AM   #16
rebelbuttmunch
LQ Newbie
 
Registered: Sep 2011
Posts: 15

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by grail View Post
Well I am curious how your solution has worked? Based on both input sets you provided, none of your awk outputs return accurate data
That was just a pseudo code solution I suppose. I don't want to post the real data as it could be industry sensitive.
 
Old 05-01-2014, 10:47 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I was not asking for any extra data. What I said was, it does not work with the data as posted or in the current format.

Are you able to alter the data you have presented to show the format it would need to be in to work with your solution?
 
Old 05-01-2014, 11:05 AM   #18
rebelbuttmunch
LQ Newbie
 
Registered: Sep 2011
Posts: 15

Original Poster
Rep: Reputation: Disabled
It works because each NVP has is formatted the same i.e name:value, so I can use awk to get the value because each value is preceeded by its name and followed by a comma.

Code:
a=$(echo "Apples :8, Bananas :1, Kiwis: 9, Coconuts: 11" | awk -F'Apples :' '{print $2}' | awk -F',' '{print $1}')
b=$(echo "Apples :8, Bananas :1, Kiwis: 9, Coconuts: 11" | awk -F'Bananas :' '{print $2}' | awk -F',' '{print $1}')

echo "Apples $a, Bananas:$b,"

Apples 8, Bananas:1,
 
Old 05-01-2014, 11:11 AM   #19
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by rebelbuttmunch View Post
It works because each NVP has is formatted the same i.e name:value, so I can use awk to get the value because each value is preceeded by its name and followed by a comma.

Code:
a=$(echo "Apples :8, Bananas :1, Kiwis: 9, Coconuts: 11" | awk -F'Apples :' '{print $2}' | awk -F',' '{print $1}')
b=$(echo "Apples :8, Bananas :1, Kiwis: 9, Coconuts: 11" | awk -F'Bananas :' '{print $2}' | awk -F',' '{print $1}')

echo "Apples $a, Bananas:$b,"

Apples 8, Bananas:1,
there must be a typo in your original post which made us think that ':' or ',' could be used as a delimiter for fruit:number groupings.
 
Old 05-01-2014, 11:36 AM   #20
rebelbuttmunch
LQ Newbie
 
Registered: Sep 2011
Posts: 15

Original Poster
Rep: Reputation: Disabled
Apologies!
 
  


Reply

Tags
awk, bash, find, scripting, sed



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
display a row of data from a database in a table format 3vra Programming 2 03-13-2009 10:25 AM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM
how to get the second column and first row data from a file??? loplayers Linux - Newbie 3 11-05-2007 07:35 PM
mysql alter row data kpachopoulos Programming 8 09-26-2007 02:54 AM
Simple sh script: rand reorder Sinope Programming 2 09-11-2004 05:24 PM

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

All times are GMT -5. The time now is 11:34 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
Open Source Consulting | Domain Registration