Using echo in AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using echo in AWK
# 8  
Old 03-12-2009
Quote:
Originally Posted by jermaine4ever
Hello,
I have written the script below to extract specific data from a text file and then use the data extracted as parameters for another shell script call 'loto_tsim'.
Everytime I run my script it complains about the 'echo' line. Am I missing something? I have spent hours and still cannot solve this, can anyone help?

Please put code inside [code] tags.
Quote:
Code:
 
#!/bin/sh
 
awk 'NR==1 {n = split($3, array, "-");
lotoE="1\n 20\n 0\n 0\n 1\n 1\n 7\n 0\n array[1]\n array[2]\n array[3]\n array[4]\n array[5]\n array[6]\n 1\n 1\n 0\n 0\n 0\n N\n 1\n 100\n"
 
echo ${lotoE} | $LOTO/bin/loto_tsim > /dev/null 2>&1


There is no echo statement in awk; use print or printf.

You also cannot use shell variables inside awk. Pass them to awk with the -v option:

Code:
awk -v var="$3" 'NR==1 {n = split(var, array, "-") ...'

Quote:
Code:
 
}' LottWagers2.txt

----------------------THIS IS THE ERROR------------------------------
Syntax Error The source line is 6.
The error context is
echo >>> ${ <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 6.

But, as radoulov pointed out, why use awk?
# 9  
Old 03-12-2009
The problem with this is that I only want to read in the the 01-02-25-26-27-28 and then split teh number in 01 02 25 etc because the tSim only accept one digit at a time


1 1 01-02-25-26-27-28 (99) Both 1
# 10  
Old 03-12-2009
Quote:
Originally Posted by jermaine4ever
The problem with this is that I only want to read in the the 01-02-25-26-27-28 and then split teh number in 01 02 25 etc because the tSim only accept one digit at a time

1 1 01-02-25-26-27-28 (99) Both 1

Code:
read a b c d < LottWagers2.txt
IFS=-
set -- $c
printf "%s\n" "$@" | "$LOTO"/bin/loto_tsim

# 11  
Old 03-12-2009
Thank you very much OH GREAT MASTERS. I will try this and see if it work.
Darn I will have to do this in the morning some trigger finger just killed the whole system to I cannot get on.
But thank you guuys very much, hopefully it works in the morning
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to save output of echo and awk to a file

Hi, I am generating a YAML file from a hosts file, but am having trouble saving it to a new file. hosts file 127.0.0.1 localhost 192.168.1.2 host1 192.168.1.3 host2 192.168.1.4 host3 192.168.1.5 host4 YAML file $ echo 'host_entries:' && awk '{printf " %s:\n ip:... (3 Replies)
Discussion started by: sand1234
3 Replies

2. Shell Programming and Scripting

Grep echo awk print all output on one line

Hello, I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it. I've been asked to write a script that pulls a list of our CPE... (51 Replies)
Discussion started by: rwalker
51 Replies

3. Shell Programming and Scripting

Echo awk output from its variable

Stumped with the formatting of the awk output when used with variables, e.g.: awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1 produces the desired output (with rows), but when echoing the variable below, the output is one continuous line var1=$(awk -F, 'BEGIN {OFS=","} print... (4 Replies)
Discussion started by: ux4me
4 Replies

4. Shell Programming and Scripting

Combining echo and awk

i have a script that has many lines similar to: echo $var | awk -F"--" '{print $2}' as you can see, two commands are being run here. echo and awk. id like to combine this into one awk statement. i tried: awk -F"--" "BEGIN{print $var; print $2}" but i get error messages. (10 Replies)
Discussion started by: SkySmart
10 Replies

5. Shell Programming and Scripting

Unable to echo single quotes inside awk

# echo 'export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk '{print \$1}')' >> new_file # # cat new_file export HISTFILE=/var/log/history/history_$(uname -n)_$(date +%Y:%b:%d:%H:%M)_$(who am i | awk {print $1}) # Now how to echo the quotes around the... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. Shell Programming and Scripting

Problem with writing to output - awk, echo

Hello all, I wrote this command line for some calculation on my given input files based on another input file which is a txt file. while read BAM REGION; do samtools view $BAM $REGION | awk '{if ($2==0) print $0}' | wc -l >>log.txt; echo "$REGION"; done >> log.txt <regions.txt It takes... (4 Replies)
Discussion started by: @man
4 Replies

7. Shell Programming and Scripting

Improve performance of echo |awk

Hi, I have a script which looks like this. Input file data1^20 data2^30 #!/bin/sh file"/home/Test.txt" while read line do echo $line |awk 'BEGIN { FS = "^" } ; { print $2 }' echo $line |awk 'BEGIN { FS = "^" } ; { print $1 }' | gzip | wc -c done <"$file" How can i... (4 Replies)
Discussion started by: chetan.c
4 Replies

8. Shell Programming and Scripting

perform echo and awk inside a string

hi, just wanted to make a shortcut of this one a="a b c" b=`echo $a | awk '{print $2}'` echo "the middle is $b" why can't i do this: a="a b c" echo "the middle is ${`echo $a | awk '{print $2}'`}" <- bad substitution :wall: thanks (6 Replies)
Discussion started by: h0ujun
6 Replies

9. Shell Programming and Scripting

awk to echo ???

Hi All, I have the below command. awk 'BEGIN {printf("%1s","cat")}' > temp.txt can i do the same using echo ?If So, how? Thanks JS (2 Replies)
Discussion started by: jisha
2 Replies

10. UNIX for Dummies Questions & Answers

echo is too slow. HELP with Awk

Hello All, Below is a simple script i worte to find the 208th char in a file. If the char = "C" then I re-direct the line to a file called change.txt. If it is not "C" then I re-direct it to a file called delete.txt. My problem is I have a file 0f 500K lines. this script is very slow. I am... (4 Replies)
Discussion started by: eja
4 Replies
Login or Register to Ask a Question