Help with Script using Command Blocks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Script using Command Blocks
# 1  
Old 12-15-2009
Error Help with Script using Command Blocks

Hello,
I am trying to create a shell script that use command block (donīt really know if this is the correct way to say it), but while one version works fine, the other one is not working at all.
So let me show an example of this "command block" Iīm using and its working ok:
Code:
cat << _EOF_
`echo "All informations regarding Brand Split log. It is in order regardless it shows no date."`
`echo`
`echo "Activations:"`
`grep "^8:Mass40s --" brand_split_file`
`grep "^9:Mass --" brand_split_file`
`grep "^10:Mass Promo --" brand_split_file`
`grep "^11:Jovem --" brand_split_file`
`grep "^12:Corporate --" brand_split_file`
`grep "^13:VIP --" brand_split_file`
_EOF_

This next one is not working:
Code:
monday=`awk -F";" '{print$1}' tmp |sort -u |tail -7 |head -1`

echo $monday
cat << _EOF_
`echo "Deletion by SC on $monday"`
`echo "Mass40s : `awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l`"`
`echo "Mass : `awk -F";" '$1=="'$monday'" && $4==4' tmp |wc -l`"`
`echo "Mass Promo : `awk -F";" '$1=="'$monday'" && $4==3' tmp |wc -l`"`
`echo "Jovem : `awk -F";" '$1=="'$monday'" && $4==42' tmp |wc -l`"`
`echo "Corporate : `awk -F";" '$1=="'$monday'" && $4==6' tmp |wc -l`"`
`echo "VIP : `awk -F";" '$1=="'$monday'" && $4==5' tmp |wc -l`"`
`echo "Prestigio : `awk -F";" '$1=="'$monday'" && $4==48' tmp |wc -l`"`
`echo "Reactivation : `awk -F";" '$1=="'$monday'" && $4==46' tmp |wc -l`"`
`echo "Postpaid : `awk -F";" '$1=="'$monday'" && $4==1' tmp |wc -l`"`
`echo "T+ Employee : `awk -F";" '$1=="'$monday'" && $4==10' tmp |wc -l`"`
`echo "Stock : `awk -F";" '$1=="'$monday'" && $4==18' tmp |wc -l`"`
`echo "Paris : `awk -F";" '$1=="'$monday'" && $4==40' tmp |wc -l`"`
`echo "Boston : `awk -F";" '$1=="'$monday'" && $4==41' tmp |wc -l`"`
`echo "Sal : `awk -F";" '$1=="'$monday'" && $4==43' tmp |wc -l`"`
`echo "TC101 : `awk -F";" '$1=="'$monday'" && $4==101' tmp |wc -l`"`
`echo "TC102 : `awk -F";" '$1=="'$monday'" && $4==102' tmp |wc -l`"`
`echo "TC106 : `awk -F";" '$1=="'$monday'" && $4==106' tmp |wc -l`"`
_EOF_

This is the error output:
Code:
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file

If you compare the two codes you will notice that while the first code has only one command ( grep ), the second has two ( echo first, and then awk ), so Iīm guessing that is the problem... which is strange because if I use the `caracters` it is supose to accecpt it like a command. I have others scripts that use this.

So if you could give me a hint on how to solve this, I would be very gratefull. I'm kind on a hurry, since I making a series of script to run automatically during my well earned vacations.... (about to go crazy with all this work!)

Thank you guys!Smilie
# 2  
Old 12-15-2009
What a mess Smilie

You try to nest backticks ` ` into another. Problem is, that the line is not completely parsed so the 1st starting backtick is ended by the second, not the 4th.

I'd just write a normal shell script. HERE-Skripts that you feed with input are usually used for ftp scripts etc. Using this method in this particular case I see no benefit.

Also this can be written much more compact supposedly with 1 awk script for example. You can echo stuff with awk's print and printf as you already do and wc can be done by awk too. grep'ing of course can be done by awk too.
# 3  
Old 12-15-2009
Bug Big mess indeed!!

Hi there zaxxon
I know it is a mess (big time!), but this is just one part of the script and I chose to use command blocks because its server me better (I think) this way, because the output format is important since it will be used for treatment later on in the script.
So if it is possible, do you know of any way to nest the backtick in a correct form so it will not end with the first one but the last one?
Meanwhile I will try to follow your suggestion by rewriting the script without the blocks.
Thank you for your fast replay!
# 4  
Old 12-15-2009
if you use the $( .. ) syntax in place you'll then be able to nest them.
# 5  
Old 12-15-2009
No result yet.....

Quote:
Originally Posted by frans
if you use the $( .. ) syntax in place you'll then be able to nest them.
Hi there,
In place where? I tried (in different positions) already but it seems to ignore the $(...) syntax altogether and produce a similar error output:
Code:
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file
./the_script: command substitution: line 1: unexpected EOF while looking for matching `"'
./the_script: command substitution: line 2: syntax error: unexpected end of file

# 6  
Old 12-15-2009
In state of
Code:
`echo "Mass40s : `awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l`"`

try
Code:
$( echo "Mass40s : $(awk -F";" '$1=="'$monday'" && $4==44' tmp |wc -l)")

# 7  
Old 12-15-2009
MySQL Perfect!!

Frans,
It worked perfectly! I thought that only backtick (`) should be used in this type of command build, but $(..) syntax is good also, perfect for this situation.

So Frans and Zaxxon thank you very much for you help and time.

Take care!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Can I run repair on lot of blocks with single command ?

Hi, I have Solaris-10 OS on T5220. Both local disks were mirrored under SVM. Somehow when one disk gone bad (c0t1d0), other disk (c0t0d0) also got lot of bad block. We have readable data only on c0t0d0, but as soon as server comes after, it hangs when I run few commands because of read errors,... (1 Reply)
Discussion started by: solaris_1977
1 Replies

2. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

3. Shell Programming and Scripting

Blocks into table

please help, I have a huge file with blocks of data which I need to convert to a tabular format. Input sample id: GO:0000017 name: alpha-glucoside transport namespace: biological_process def: "The directed movement of alpha-glucosides into, out of or within a cell, or between... (3 Replies)
Discussion started by: ritakadm
3 Replies

4. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

5. Shell Programming and Scripting

Dividing tab blocks in bash script

Hi everyone, I have a data.xml file which only contains thousands of data (tag) blocks. A part of the file looks exactly like this; <data> Line Line Line </data> <data> Line Line Line </data> the rest of the file is simply a repetition of this part. Here each data block contains a... (8 Replies)
Discussion started by: hayreter
8 Replies

6. UNIX for Dummies Questions & Answers

Command rm deletes filename but not the blocks

Hi It happens when I try to delete a file of 250MB with the command rm -r on our old Intergraph CLIX that the filename disappears while the blocks remain on the machine. Only when I reboot the system the blocks really disappear. Then rm works again for sometime but after some time it happens... (15 Replies)
Discussion started by: hausi2012
15 Replies

7. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

8. UNIX for Dummies Questions & Answers

Convert 512-blocks to 4k blocks

I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how? So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Discussion started by: rockycj
2 Replies

9. UNIX for Dummies Questions & Answers

ls -l (without showing total blocks)

Is it possible to use the ls command and NOT see the total blocks? For example, instead of seeing this... $ ls -l total 16 drwxr-xr-x 2 voicem voicem 4096 Dec 3 09:19 directory1 drwxr-xr-x 2 voicem voicem 4096 Dec 1 01:29 directory2 drwxr-xr-x 2 voicem voicem 4096 Dec 2 00:47 directory3... (5 Replies)
Discussion started by: cdunavent
5 Replies
Login or Register to Ask a Question