Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using awk in a script...

Status
Not open for further replies.

bondtrails

Technical User
Nov 19, 2002
31
US
Hi everyone,
I can't seem to get shell quoting correct in a unix script.
I tried this command in the command line, and it works great:

awk -v file="input1.dat" -f program.awk input2.dat > output.dat

but i can't seem to make it work in a script--I've tried a few quoting combination but so far no go. Here's what I've got:

#! /bin/sh

FILE_1=$1
FILE_2 =$2
OUT=$3
DIR="/Volumes/data store/current files"

COMMAND=awk
PARM'-v fna='"$DIR/$FILE_1"' -f program.awk'

$COMMAND $PARM "$DIR/$FILE_2" > "$DIR/$OUT"

this doesn't work the way it should! Can someone help out??
--Bondster!!
P.S. note that in the line defining PARM, double quotes surround the $DIR/FILE_1 (not 3 single quotes, as it may seem)
 
Oops! Forgot the "=" in after parm. It should read:
PARM='-v fna='"$DIR/$FILE_1"' -f program.awk'

It still doesn't work though :-(

--Bondster
 
bondtrails
learn the correct use of " ' { } and so on
do not abuse of them, you are confusing yourself
in your post ALL " are useless.

if you use spaces in filenames (in unix) you will
EVER get troubles and have to handle them correctly

on cmd-line: ls -l "aaa bbb"
in scripts: ls -l \"aaa bbb\"
and: DIR="\"aaa bbb\"" ; ls -l $DIR

all show infos about ONE file called "aaa bbb" -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Hey thanks Jamisar,
I think your simple example clarified the rules behind quoting. Geez, I wish the book I was reading used similar examples. Anyway, I changed my script and it worked well.

I'll probably wind up asking for help again in the near future, but I figure with all this practice, It will come easier.

--Bondster!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top