Bash script issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script issues
# 1  
Old 04-26-2010
Bash script issues

Hi.

The below part of my bash script kicks out the following error message:

Code:
[user@test01-stage-btv cmd]$ ./extract_eod_report_stats_new.sh 2010-04-23
./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `('
./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep -v 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{if(x<$5) {x=$5;y=$3}} END {printf y}'`'

I have debugged the failing row (and the surrounding rows) for quite some time without being able to pinpoint the problem.

I would be very grateful for help.

Best regards,
Peter Lovell

Code:
...
TRANSACTIONS_RECEIVED=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{x+=$5} END {printf x}'`
TRANSACTIONS_PUBLISHED=`grep 'Transactions' $OUTPUT_FILE_PERF_TXD | grep 'AllFirms' | grep 'TXD1' | sed s/'"'/''/g | awk -F "," '{print $5}'`
TRANSACTIONS_PRICE_ERRORS=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{x+=$6} END {printf x}'`
TRANSACTIONS_QTY_ERRORS=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{x+=$8} END {printf x}'`
TRANSACTIONS_REJECTED=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{x+=$10} END {printf x}'`
TRANSACTIONS_CANCELLATIONS=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{z=$11+$12; x+=z} END {printf x}'`
TRANSACTIONS_AMENDMENTS=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{z=$13+$15;x+=z} END {printf x}'`

TRANSACTIONS_RECEIVED_TOP=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep -v 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{if(x<$5) {x=$5;y=$3}} END {printf y}'`

TRANSACTIONS_RECEIVED_TOP=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep -v 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," '{if(x<$5) x=$5} END {printf x}'`
TRANSACTIONS_RECEIVED_LOW=`grep 'Transactions' $OUTPUT_FILE_TRANSACTIONS | grep -v 'AllFirms' | grep "TX[24]" | sed s/'"'/''/g | awk -F "," 'BEGIN {x=999999999} {if(x>$5) {x=$5;y=$3}} END {printf y}'`
...


Last edited by zaxxon; 04-26-2010 at 11:36 AM.. Reason: use code tags please, ty
# 2  
Old 04-26-2010
what are some of the lines above 204? maybe lines 194-204 would help as well.
# 3  
Old 04-27-2010
Many thanks for your reply

I have attached the whole script.

The script might look slightly different from my earlier posting since I have edited names of variables.
The same error message still occur though.
# 4  
Old 04-27-2010
IMHO the error is here:
Quote:
*) (
) >&2 exit 1
;;
esac
I can reproduce the error message by including this code in a simple "case" statement. Just remove the excess brackets etc. which were probably intended to create a sub-shell for error messages?


None of the code in Post #1 appears in the script attached to Post #3 . There is no mention of TX[24] whether or not the variable names have changed. The error messages cannot be "the same".

Please post script and matching error messages from running that script.

For debugging consider running as "bash -x" or even commenting out lines from the bottom up until the error disappears.

Btw: The huge sed pipeline (30+ lines long) towards the end of the script will need attention. I can't see any line continuation characters "\" . Hopefully is it not one continuous wrapped line?

Btw: The main script structure reads the same files umpteen times. If these files are of any size it could be slow.
# 5  
Old 04-27-2010
Thanks for the reply.

I get the error message even if I update the case clause. I also tried to comment out the whole case clause and the error message still appear:

Code:
[user@test01-stage-btv cmd]$ ./extract_eod_report_stats_new.sh 2010-04-23
./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `('
./extract_eod_report_stats_new.sh: line 204: `TRADES_RECEIVED_TOP_CONTRIBUTOR_NAME=`grep 'Trades' $OUTPUT_FILE_TRADES | grep -v 'AllFirms' | grep "ME[24]" | sed s/\"/''/g | awk -F "," '{if(x<$5) {x=$5;y=$3}} END {printf y}'`'


Anymore ideas?

Last edited by vgersh99; 04-27-2010 at 01:04 PM.. Reason: code tags, please!
# 6  
Old 04-27-2010
(Post rewritten). The sed statements to remove double quotes could be replaced with "tr" to make the script easier to read. This is not the main issue.

Code:
tr -d '"'



---------- Post updated at 18:46 ---------- Previous update was at 17:49 ----------

At last!

This line is decidedly suspect and turns half the script into a "sed" statement.

Quote:
OUTPUT_FILE_QUOTES="$COLLECT_DIR"/"$OUTPUT_FILE_PREFIX"_me_| sed s/'QUOTES_stats.csv

Last edited by methyl; 04-27-2010 at 02:47 PM.. Reason: Rewritten post.
# 7  
Old 04-28-2010
YES! Spot on Methyl!

The script works again.
Many many thanks Methyl!!!
I also appreciate the other comments about my script, I will update it accordingly.
Cheers.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

Bash/cron issues

Hi all, I am trying to run a cronjob to push my files to my git repo once a week and output a prompt to a logfile, my script works fine if I invoke it manually but my cronjob wont run for some reason, I have sourced the file, and restarted my Mac to no avail, right now I believe I have the cronjob... (8 Replies)
Discussion started by: gmenfan83
8 Replies

4. Shell Programming and Scripting

Bash Case Issues..

Hi, I'm having some trouble with using "case...esac" in Bash. I've googled it and am stuggling to understand the syntax and how to do certain things. Firstly, I want to be able to choose a case based on a variable number For example, I have in my code a place where a user can enter... (2 Replies)
Discussion started by: Ste_Moore01
2 Replies

5. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

6. Shell Programming and Scripting

Unix bash script (mv issues);

Hey guys, I've registered here as I need urgent help. This is assignment for school and as you can see below I've completed the work. I'm simply stuck on one area. :wall: This script takes the first parameter (which is to be the new extension) and each parameter after that is a file... (1 Reply)
Discussion started by: Cynosure
1 Replies

7. Shell Programming and Scripting

Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this: - , for directories. - , for files. I want to do something like this: , for directories. , for files. This is my code: #!/bin/bash for fname in *.mp3; do echo item: $fname mv... (2 Replies)
Discussion started by: josco1982
2 Replies

8. Shell Programming and Scripting

Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them. I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so... (3 Replies)
Discussion started by: alindner
3 Replies

9. Shell Programming and Scripting

for / foreach syntax issues (in bash or tcsh)

So I am new to unix, and actually anything outside drag and drop with the mouse (been learning for about a week so far) . I have been using the foreach command in tcsh because I am working on a group of files. Basically what I need is to insert part of the filename as the first line in the file.... (0 Replies)
Discussion started by: thepolypore
0 Replies

10. UNIX for Dummies Questions & Answers

IP connection Bash script issues

Hello I need assistance with a bash script that needs to tell me whether in the last "x" days (which is a variable) anyone connected to the xxxx IP (which is another variable). Thank you! (1 Reply)
Discussion started by: Melchiah
1 Replies
Login or Register to Ask a Question