(standard_in) 1: parse error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting (standard_in) 1: parse error
# 1  
Old 02-15-2014
[Solved] (standard_in) 1: parse error

Hi,

I am trying to make a script that tries to compare two values and print if one is greater than another. It seems to return a (standard_in) 1: parse error at times.

Code:
#!/bin/sh
a= awk '{print $1}' file1.txt
b= awk '{print $1}' file2.txt
c= awk '{print $1}' file3.txt

x= awk '{print $1}' file4.txt
y= awk '{print $1}' file5.txt
z= awk '{print $1}' file6.txt

if [ "$x" == "" ]
then
        x=1000
elif [ "$y" == "" ]
then
        y=1000
elif [ "$z" == "" ]
then
        z=1000
fi

echo "$a>$x" | bc
echo "$b>$y" | bc
echo "$c>$z" | bc

Files 1-6 have numbers in them and if some value in x y z are missing I want to replace it by a large number so that x y or z is always greater than a b or c.

Can someone find out whats wrong here.
# 2  
Old 02-15-2014
What is the structures of these input files? Is there only one number in them? If so, is there a reason you are using files for input?

To put the output of a variable into variable:
Code:
var=$(cmd)

no space is allowed around the equal sign

The equation uses a single =

You can also use variable expansion to make sure a variable becomes 1000 when empty:

Code:
echo "$a>${x:=1000}"


Last edited by Scrutinizer; 02-16-2014 at 08:59 AM.. Reason: changed x:- to x:=
# 3  
Old 02-16-2014
Hi,

Thanks for the response. The reason that I use files it because it has been generated earlier.

I made the suggested changes, still seem to be getting the same error. It happens whenever the line is empty. Below is the script

Code:
#!/bin/sh
for name in */
do
echo $name

a=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "The url for " |awk '{if (NR==2) {print}}' | awk '{print $1}')
b=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "The url for " |awk '{if (NR==3) {print}}' | awk '{print $1}')
c=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "The url for " |awk '{if (NR==4) {print}}' | awk '{print $1}')

x=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "download info" | grep '21$'| awk '{print $1}')
y=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "download info" | grep '40$'| awk '{print $1}')
z=$(cat $name/num1/New\ folder/processing_new/final.txt | grep "download info" | grep '59$'| awk '{print $1}')
if [ "$x"="" ]
then
        x=1000
elif [ "$y"="" ]
then
        y=1000
elif [ "$z"="" ]
then
        z=1000
fi

echo "$a>$x" | bc
echo "$b>$y" | bc
echo "$c>$z" | bc
done

# 4  
Old 02-16-2014
In assignment there should not be a space around the equal sign. but in comparisons there should be :
Code:
if [ "$x" = "" ]

The way the values are extracted from the files into the variables is highly inefficient and this will produce a slow script. What do these files look like and how many are there?
# 5  
Old 02-16-2014
The file is usually a few thousand lines long but I will be dealing with only 15 or so files at a time. A sample line is below.

Code:
11.1 Sat Feb 15 2014 06:05:00 PM.026 [DEBUG]  [org.osmf.net.httpstreaming.f4f.HTTPStreamF4FIndexHandler] The url for ( time=0, quality=0) = [HTTPStreamRequest kind=download, url=http://ip.add.re.ss/vod/final_0.25Seg1-Frag1]

Out of the lines which match with the grep I know the line at which the interesting ones are, so I just print them out and just get the first column which is a time stamp.

Also with no space around assignment and space around comparison, I still get the same error as before.

Thanks.!

---------- Post updated at 02:48 PM ---------- Previous update was at 02:44 PM ----------

Code:
echo "$a>${x:=1000}"

This seems to fix the problem. Could you explain this if it is not asking too much.

Thanks.
# 6  
Old 02-18-2014
Hi,

in the input data, I noticed that both either a b c or x y z could be empty.

So I changed the comparison line to:

Code:
echo "${a:=1000}<${x:=1000}" | bc 
echo "${b:=1000}<${y:=1000}" | bc
echo "${c:=1000}<${z:=1000}" | bc

Was hoping that this would do the trick, but when given an input

Code:
22.2
40.8
59.2

36.5
53.7

it returns me
Code:
1
0
1

While it should have been
Code:
1
0
0

.

I am not sure if I understand things right here. Could you please help.

Edit: Fixed the problem, was a mistake with variable names that I was using...Sorry..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

(standard_in)1:syntax error using bc with Cron

I created a shell script to record server temperature. When I manually run script it works fine with no error message. But when I create a cron job, my script fails with error message (standard_in)1:syntax error. I figured out the bc utility is causing the error message. Below is my script. ... (7 Replies)
Discussion started by: SysAdminRialto
7 Replies

2. Shell Programming and Scripting

Standard_in error

# echo '6.5 < 2.7 ' |bc 0 # echo '4.8.5 > 4.8.4' |bc (standard_in) 1: syntax error (standard_in) 1: syntax error ---------------------------------------------------------- FILESET_A_VER_CHK2=4.8.5 FILESET_R_NAME_CHK2=4.8.5 if ] ; then ## echo "Fileset is higher " ... (2 Replies)
Discussion started by: Mathew_paul
2 Replies

3. Shell Programming and Scripting

Parse

Attached file is parsed so that only the three columns result. DACH1 occurs 34 times with an average of 0.881541 NEB occurs 159 times with an average of 0.837628 LTBP1 occurs 46 times with an average of 0.748722 parse result: output.txt (the text is removed and the xxx is seperated in a... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

intermittent bc parse error

Thought I had this worked out, and the equations work fine on their own. What I have is an if statement that checks the raw size of a folder. Smaller than a certain threshold and it returns a value in MB format, otherwise it returns it in GBs. Yes, I know that df and du return human readable... (3 Replies)
Discussion started by: reid
3 Replies

5. Shell Programming and Scripting

bc giving error: (standard_in) 2: parse error

Below part of script, is working fine sometimes and gives error sometime. I am doing float operations, checking if x > y. ##########CODE########## THRESHOLD="1.25" ratio=$( echo "scale=2; ${prev}/${current}" | bc ) if ; then split_date=`echo ${line} | cut -d, -f2` fi ... (9 Replies)
Discussion started by: manishma71
9 Replies

6. Shell Programming and Scripting

(standard_in) 1: parse error

Hi all, Could someone please to tell me when do we exactly get the below error and how to get rid of it. I am unable to trace the error. (standard_in) 1: parse error Thanks in advance !! (4 Replies)
Discussion started by: sparks
4 Replies

7. Shell Programming and Scripting

Perl parse error

Hello there, I em executing the following command in a perl script to append "\0" to the end of every line in a file: ###command start my $cmd = qx{"C:\\gawk" '{print $0 "\\\0"}' C:\file.txt > C:\file_1.txt}; ###command end But i get the following error: ###error meaasge start... (2 Replies)
Discussion started by: nmattam
2 Replies

8. Shell Programming and Scripting

Parse

I need a script that will always return an engine of table, which not depends on the table structure. I need it to be done exactly from the "show create table ..." statement. If there is a easiest way, except "show table status", please write. mysql -u root db -sBe "show create table... (1 Reply)
Discussion started by: mirusnet
1 Replies

9. UNIX for Advanced & Expert Users

Parse error

hi,:) onsider the followinf two lines J="$(scriptbc -p 8 $I / \(12 \* 100 \) )" N="$(( $L * 12 ))" In the first line I put \ before * like \* and its working fine. But in the second line if put \ before * i am getting parse error. What might be the reason?Any idea pls. cheers RRK (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

10. Shell Programming and Scripting

Parse

Does anybody know how do we parse a file (ex. SIF file) into a delimited text file in UNIX? (7 Replies)
Discussion started by: nguda
7 Replies
Login or Register to Ask a Question