Using echo in AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using echo in AWK
# 1  
Old 03-12-2009
Using echo in AWK

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?

#!/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

}' 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.
# 2  
Old 03-12-2009
It's because there is not an echo statement in awk ...
# 3  
Old 03-12-2009
Thanks radoulov. Would you happen to know how I can resolve this?
# 4  
Old 03-12-2009
Yes,
if you try to explain what exactly you are trying to achieve.
Could you post a sample of the LottWagers2.txt file content and an example of the $LOTO/bin/loto_tsim output.
# 5  
Old 03-12-2009
Hello Radoulov,
the subset of the text file content is below. the loto_tsim was written by someone else and works perfectly, allowing the user to enter specific information from and then the simulator does some processing in the background. The problem is that the original script were using static values, but some of the ebrty we need to be generic hence the reason why I am reading some of the values from a defined test file.

-----Format of Content of text file -----
1 1 01-02-25-26-27-28 (99) Both 1
1 1 26-27-28-29-30-31 (31) Both 1
1 1 01-02-27-28-29-30 (99) Both 1
1 1 01-02-03-04-05-06 (99) Both 1
# 6  
Old 03-12-2009
loto_sim (another shell script someone else wrote) is expecting certain values to be entered from teh command line. the values I am supplying are in lotoE. If I was not using awk, I could have echo the values in, but becuse I used awk to read in specific data from a text file, I don't think awk understands 'echo'
# 7  
Old 03-12-2009
If you really need to read only the first line of LottWagers2.txt,
something like this may work:

Code:
( read a b c d< LottWagers2.txt
  IFS=-
  printf ' 1\n 20\n 0\n 0\n 1\n 1\n 7\n 0\n'
  printf ' %s\n' $c
  printf ' 1\n 1\n 0\n 0\n 0\n N\n 1\n 100\n' ) | 
  "$LOTO"/bin/loto_tsim > /dev/null 2>&1

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