rcbatlinux
Technical User
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
*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