Linux, C-shell, save Awk string output to a variable and preserve special characters in string

91 views Asked by At

I have a csv file with string data.

The string, 1000/06{a-09}90.log, is in row 236 and column 6.

I tried to save the string in a variable using the command below. This command doesn't preserve the curly brackets.

set var = `awk -F ',' 'NR==236{print $6}' File.csv`

echo $var results in: 1000/06a-0990.log <- missing {}

How can I save the string and preserve the special characters?

1

There are 1 answers

12
Philippe On

Curly braces are for brace expansion, that's why they are removed.

Use double quotes to prevent brace expansion:

set dollar6='$6'
set var = "`awk -F ',' 'NR==1{print $dollar6; exit}' File.csv`"
echo "$var"