0

a have a pipe delimited file where the 4th column is a text column which are strings that occasionally contain shell script wildcard characters.

Data File:a.dat

A|d|E|"G"

A|B|C|"SEL * FROM TABLE1;"

A|B|C|"SEL * FROM TABLE1;"

I would like to read the file line-by-line and assign each column to a different variable and then print those variables to ab HTML tag to show it in ab HTML report.

I am facing a problem where the 4th column have wild chars like *

while read LINE

do 

echo -e $LINE

StartTime=`echo -e $LINE | cut -d "|" -f1`

UserName=`echo -e $LINE | cut -d "|" -f2`

AppID=`echo -e $LINE | cut -d "|" -f3`

QueryText=`echo -e $LINE | cut -d "|" -f4-10`

echo -e "$QueryText"

done < a.dat

It is printing 4th column but replacing * with all the unix local files located in the script's directory.

How can I only print the 4th column values as is?

ashawley
  • 4,195
  • 1
  • 27
  • 40
somu
  • 11
  • 2
  • You need to put quotes around `$LINE` everywhere, just like when you do for `"$QueryText"` – ashawley May 05 '17 at 03:17
  • Adding quote for $LINE worked. Thx – somu May 05 '17 at 03:30
  • The repeated `echo | cut` is an antipattern, too. You want `while IFS='|' read -r StartTime UserName AppID QueryText; do`... – tripleee May 05 '17 at 04:02
  • I did consider IFS='|' over cut but the issue i found when 4th cloumn which contains SQL stmt contains | in it. Example: sel col1||col2||cou3 from table; Using cut i can grab any columns from 4th to 100. Please let me know if there is any options to do it using IFS – somu May 07 '17 at 16:36

0 Answers0