0

I am defining the following variables inside a bash script (note: I ultimately want to pass these values to the bash script from the commandline but I haven't gotten that far yet):

OFS=','
INPUTFILE='~/data.txt'
OUTPUTFILE='~/delimited.txt'
FIELDWIDTHS='1 10 4 2 2'

Next, inside the bash script I'm attempting to call an awk script and pass it these same values:

echo
echo | awk -v FIELDWIDTHS=$FIELDWIDTHS -v OFS=$OFS
 -v INPUTFILE=$INPUTFILE -v OUTPUTFILE=$OUTPUTFILE
 -f ~/bin/fixedWidthToDelimited.awk

The awk script doesn't seem to be able to understand correctly what's being passed to it, I keep getting fatal errors. Can someone please help me understand how to do this? Thanks!

3
Contributors
2
Replies
12
Views
5 Years
Discussion Span
Last Post by cfajohnson
0

It would be better to let the shell expand the tilda by removing the quotes or use $HOME with double quotes, because awk probably doesn't expand a tilda.

0

Quote the variable references:

awk -v FIELDWIDTHS="$FIELDWIDTHS" -v OFS="$OFS" -v INPUTFILE="$INPUTFILE" -v OUTPUTFILE="$OUTPUTFILE"

Edited by Dani: Formatting fixed. Please indent code using Markdown instead of [code] bbcode (which isn't supported).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.