Computing.Net > Forums > Unix > parsing returned data

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

parsing returned data

Reply to Message Icon

Name: jcarrott
Date: March 26, 2009 at 08:28:01 Pacific
OS: AIX UNIX
Subcategory: Software Problems
Comment:

I used the command
company=`cut -d, -f2 $FaxFile`
echo $company
The echo contains "P VENDOR-NAME". I am getting the second column from line one which contains "P" and the second column from the second line which contains the VENDOR-NAME that I what.
How do I edit $company to remove the P and the space or just get the second column from the second line?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 26, 2009 at 08:45:36 Pacific
Reply:

There are a number of ways to do this. Use an external tool like awk to do the parsing:

!/bin/ksh

my_company=`echo "P VENDOR-NAME"|awk ' { print $2 } '`
echo $my_company

Or you can let the shell itself do it:

echo "P VENDOR-NAME"|read col1 my_company
echo $my_company

When you decide what you want to do, you can probably eliminate the intermediate variables:

# untested
company=`cut -d, -f2 $FaxFile|awk ' { print $2 } '`


0

Response Number 2
Name: James Boothe
Date: March 26, 2009 at 13:03:15 Pacific
Reply:

Or the other way, as jcarrot suggests, is to grab from the second line only.  sed will output only line #2, to be piped into the cut command.

company=`sed -n 2p $FaxFile | cut -d, -f2`

echo $company
VENDOR-NAME


0

Response Number 3
Name: jcarrott
Date: March 26, 2009 at 13:38:53 Pacific
Reply:

James your responce seems to be close. I now get P as my responce to the "echo $company". The P is the value of the first line second column.
I am trying to return the second column of the second line.


0

Response Number 4
Name: jcarrott
Date: March 26, 2009 at 13:50:47 Pacific
Reply:

James -

Great help, the value that worked was changing the 2p to a 3p.

Thank you


0

Response Number 5
Name: James Boothe
Date: March 27, 2009 at 08:52:32 Pacific
Reply:

OK, glad you got it figured out. But 3p will cause sed to print the third line. Maybe your data file starts with an empty line?

Check the total lines in the file:
wc -l $FaxFile

Print just the first line:
head -1 $FaxFile

Print just the second line:
tail +2 $FaxFile | head -1


0

Related Posts

See More



Response Number 6
Name: jcarrott
Date: March 27, 2009 at 08:56:09 Pacific
Reply:

Thank you, there was a blank first line


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: parsing returned data

help parsing data into a vCal item www.computing.net/answers/unix/help-parsing-data-into-a-vcal-item/5123.html

Scripts 4 downloading, parsing.... www.computing.net/answers/unix/scripts-4-downloading-parsing/5150.html

reading colon delimited data www.computing.net/answers/unix/reading-colon-delimited-data/5825.html