Nohsib
Nohsib

Reputation: 3712

cut operation - weird behavior

cut operation is giving unexpected results due to "*" in the input data , how to fix it..

the following will explain better :

$ line="000067     (base 16)         SOFT * RITE, INC."
$ vendoroui=`echo $line | cut -d' ' -f1`
$ echo $vendoroui
000067
$ vname=`echo $line | cut -d' ' -f4-$NF`
$ echo $vname
1 bb bn btest.txt btmp.txt cc cut if sedTbKkAE sorted start.txt t10.sh t11.sh t12.sh t13.sh t14.sh t1.sh t2.txt t3.sh t4.sh t5.sh t6.sh t7.sh t8.sh t9.sh tmp RITE, INC.

this is due to the '*' in the inPut, how to fix it??

Upvotes: 1

Views: 85

Answers (1)

Andrew White
Andrew White

Reputation: 53496

Quote your line variable...

vname=`echo "$line" | cut -d' ' -f4-$NF`

Also, when you use $vname be sure to quote it too...

echo "$vname"

Upvotes: 5

Related Questions