Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script problem

Status
Not open for further replies.

rcbatlinux

Technical User
Mar 30, 2001
80
0
0
US
Here is a script problem, wondered if anyone can help me with. I'm taking output from a report:

*05-9999 SPECIAL ORDER 1/8 DRILL 1 5.00
*21-1000 VENDOR CATALOG PART 1 2.10
APCOTEST APCO TEST 1 .00
BE1 BE1 1 5.00
BEKIT BEKIT 1 10.00

I need the part number which are the characters 4-19 and I need the price which are characters 75-85. I need to get the 4-19 characters into a variable called "partno" and the 75-85 in a variable called "price". Then I can use the variables to format my output as "partno,price" in a new fixed width format.

My problem is I can't use awk because the part number may have spaces in it and the price will not always be the "nth" position in an awk command. I tried using a cut command but can't get both into their appropriate variables. I tried the following:

cat filename | while read line
do
partno=`echo "$line" | cut -c4-19`
price=`echo "$line" | cut -c75-85`
done

But the problem is when using "read" it chops off the leading blanks so the lines get skewed slightly.

any suggestions would be great. thanks

rcbatlinux
 
Hi:

Change your field separator to something other than whitespace.

#!/bin/ksh
# tested with ksh and SCO Open Server V

while IFS="|" read line
do
partno=`echo "$line" | cut -c4-19`
price=`echo "$line" | cut -c75-85`
echo $partno
echo $price
done < f.file

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top