awk new line issue, saying string can't contain new line character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk new line issue, saying string can't contain new line character
# 1  
Old 08-30-2012
Question awk new line issue, saying string can't contain new line character

Hi ,

I am doing some enhancements in an existing shell script. There it used the awk command in a function as below :
Code:
float_expr() {
IFS=" " command eval 'awk "
BEGIN {
result = $*
print result
exit(result == 0)
}"'
}

It calls the function float_expr to evaluate two values , calculated and returned from the program like below :
Code:
if float_expr "$Amount1 != $Amount2" > /dev/null; then
   echo "AMOUNTS ARE NOT EQUAL" >> $LOGGEN/${PGM}.log
   Stat=1
   allstat=1
fi

Amount1 is 9995890.9600 and Amount2 is 9995890.96. In a seperate call Amount1 and Amount2 are passesd as 12851 and 12851.

Now if I run the entire script where the values passed in the funtion via the variable it returns the error :
awk: The string cannot contain a newline character.
The source line is 3.
The error context is
result = eval awk " >>>
<<<
syntax error The source line is 4.
awk: The statement cannot be correctly parsed.
The source line is 4.



However, I ran the same funtion in a stand alone script by passing the two values as hardcoded and it ran fine.

I am not understanding, why this has been happening and need to know a sollution to it.
I need your help on this.
# 2  
Old 08-30-2012
Code:
 
$ Amount1=9995890.9600 
$ Amount2=9995890.961

$ nawk -v a1="$Amount1" -v a2="$Amount2" 'BEGIN{if(a1!=a2){print "NOT EQUAL"}}'
NOT EQUAL

$ Amount2=9995890.96
 
$ nawk -v a1="$Amount1" -v a2="$Amount2" 'BEGIN{if(a1!=a2){print "NOT EQUAL"}else{print "EQUAL"}}'
EQUAL

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. UNIX for Dummies Questions & Answers

Appending a character(#) with string search at the start of the line

Hello, I have been browsing through the forum, but unable to find a solution for my requirement. I need to go through a file and search for /home/users and insert a # symbol at the start /home/users. Example output is #/home/users. Can you please help me with the awk or sed command for... (1 Reply)
Discussion started by: chandu123
1 Replies

3. Shell Programming and Scripting

Is shell's next line character '\' the cause of this issue ?

Oracle version: 11.2.0.1 /Red Hat Enterprise Linux Server release 5.4 (Tikanga) Hi, impdp is a command line utility in oracle to import data into a DB schema. Typically impdp command along with its parameters is run in a single line like impdp \'/ as sysdba\' DIRECTORY=DATA_PUMP_DIR... (8 Replies)
Discussion started by: omega3
8 Replies

4. Shell Programming and Scripting

gawk to remove last character in a line or string

I am outputting a line like this print $2 "/" $4The last character though is a ":" and I want to remove it. Is there any neat way to remove it? Or am I forced to do something like this: print $2 "/" substr($4, 1, length($4) - 1)Thanks. (6 Replies)
Discussion started by: benalt
6 Replies

5. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

7. Shell Programming and Scripting

awk: sort lines by count of a character or string in a line

I want to sort lines by how many times a string occurs in each line (the most times first). I know how to do this in two passes (add a count field in the first pass then sort on it in the second pass). However, can it be done more optimally with a single AWK command? My AWK has improved... (11 Replies)
Discussion started by: Michael Stora
11 Replies

8. Shell Programming and Scripting

Issue with New Line character

Hi, I am reading data from file and storing it in a multiline variable. Every line is seperated with "\n" character. globalstrval="${globalstrval}""${line}""\n" If the value of globalstrval is like: 1234 ABCD EFGH WXYZ .... If I do, YLvar=`echo $globalstrval | grep "ABC"` then... (1 Reply)
Discussion started by: gupt_ash
1 Replies

9. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies

10. Shell Programming and Scripting

error while replacing a string by new line character in sed

hi, when i am doing the following things getting error Can anyone please suggest i have a file where there is a line like the following branch=dev sdf dev jin kilii fin kale boyle dev james dev i want to search the existance of dev in the above line. cat "$file" | sed -n... (8 Replies)
Discussion started by: millan
8 Replies
Login or Register to Ask a Question