Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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_companyOr you can let the shell itself do it:
echo "P VENDOR-NAME"|read col1 my_company
echo $my_companyWhen you decide what you want to do, you can probably eliminate the intermediate variables:
# untested
company=`cut -d, -f2 $FaxFile|awk ' { print $2 } '`

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

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.

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 $FaxFilePrint just the first line:
head -1 $FaxFilePrint just the second line:
tail +2 $FaxFile | head -1

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |