Error running the script.... Help needed. Please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error running the script.... Help needed. Please
# 1  
Old 12-10-2009
Error running the script.... Help needed. Please

I have another Question:

I tried to run the following script: (I actually wanted to print out the second field in the text field.)

Code:
#!/usr/bin/ksh
set -x
readfile=/dir1/data.txt

cat $readfile | while read line
do
x = `echo $line|awk '{print $2}'`
echo $x
done

But, it shows the following error. It is unable to read the 'x' value.

Code:
# ./readData
+ readfile=/dir1/data.txt
+ cat /dir1/data.txt
+ read line
+ awk {print $2}
+ echo skhfkjshf 24343
+ x = 24343
./readData[7]: x:  not found
+ echo

+ read line
+ awk {print $2}
+ echo jsdhfklhd 94890
+ x = 94890
./readData[7]: x:  not found
+ echo


I have given all the permissions.. chmod 777 readData

Please help me out in solving this issue.

Thanks in advance.

Last edited by pludi; 12-10-2009 at 01:26 PM.. Reason: code tags, please...
# 2  
Old 12-10-2009
The assigment to the variable x may not contain spaces.
Code:
x=`echo $line|awk '{print $2}'`

# 3  
Old 12-10-2009
You can achieve the same effect with just awk.

Code:
awk '{print $2}' /dir1/data.txt


Or with just shell:

Code:
#!/usr/bin/ksh
set -x
readfile=/dir1/data.txt

cat $readfile | while read junk1 x junk2 
do
        echo "${x}"
done

# 4  
Old 12-10-2009
@ Scrutinizer:

Thank you very much...

It did work for me...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error running script

Hi, I have the the below script more runcda.sh if *\).*/\1/p' $1_dr) ]; then echo "ParallelGCThreads Found with Value" else echo "ParallelGCThreads Not Found - Add !!" fi $ ./runcda.sh output.log ./runcda.sh: test: argument expected ParallelGCThreads Not Found - Add !! Why am i... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Error in running DB query by script

Hi I was trying to fetch data from database. But the number of rows exported were huge so i got the error. Experts please advice. Thanks a lot for your supprt. #: ./script.sh ./script.sh: xmalloc: subst.c:3076: cannot allocate 1401346369 bytes (0 bytes allocated) (2 Replies)
Discussion started by: brij123
2 Replies

3. Shell Programming and Scripting

Then error while running script remotely

facing issue with then error while running a local script aginst a remote server. i facing the same issue in multiple scripts. So what i am missing here or what is needed. #!/bin/ksh echo "enter the filename" read file if then echo "file exists" else echo "file does not exists" fi ... (0 Replies)
Discussion started by: NarayanaPrakash
0 Replies

4. Shell Programming and Scripting

Error while running restart script -

Hi All I have written below basic restart script but it is giving me the following error - error - syntax error at line 40 : `else' is not matched . below is the script can someone assist me what i am doing wrong - #!/bin/ksh cd bin . ./set_sysm sleep 60 ./swstop -f 0 ... (1 Reply)
Discussion started by: honey26
1 Replies

5. Red Hat

KSH script help needed ( nice error trap routine ?)

I am running a script that runs a loop and executes a command on ${i} until the end of the for loop. From time to time the command generates an error ( which is good) for example ERROR0005: How can I trap the error and send an email echoing the ${i} variable in the loop and the error ? ... (2 Replies)
Discussion started by: pcpinkerton
2 Replies

6. Red Hat

error running postrotate script

Hi, I am getiing emails from cron.daily with subject: Cron root@vsftp run-parts /etc/cron.daily /etc/cron.daily/logrotate: /sbin/killall -HUP radiusd : line 1: /sbin/killall: No such file or directory error: error running postrotate script for /var/log/vsftpd/logfile the... (6 Replies)
Discussion started by: renuka
6 Replies

7. Solaris

Error when running script

Hi All, Need your guuys help here. #!/bin/bash { echo "POLICY LIST" echo "====================================" bppllist echo " " echo "POLICY DETAILS" echo "====================================" for type in daily weekly monthly quarterly echo... (6 Replies)
Discussion started by: ronny_nch
6 Replies

8. Shell Programming and Scripting

error in in running script

Hi all, I have created a script file .sh and had some allias commands, local variable, some grep features, and listing files/directories, and it worked correctly and I got the outputs I am looking for after I run the script . However, some of the grep commands and some other functions did not... (2 Replies)
Discussion started by: aama100
2 Replies

9. Shell Programming and Scripting

Error while running your script -- Balamv

When I run this, I am getting the below error. Why? Pls help me #!/bin/ksh echo Hello World dirs="not_using_0" for entry in *; do && dirs="$dirs $entry" done dirarray=($dirs) index=1 while }" ] ; do echo "${index}: ${dirarray}" index=`expr $index + 1` done while ; do echo -n... (1 Reply)
Discussion started by: balamv
1 Replies

10. UNIX for Dummies Questions & Answers

Error while running a script

Hi all, By running a (command) script I'm getting the following error: .: /usr/bin/test: cannot execute binary file This is the command: $ . test The script (test) is very simple sqlplus user/password @1.sql sqlplus user/password @2.sql Can enyone tell me what the problem is. (5 Replies)
Discussion started by: HarryTellegen
5 Replies
Login or Register to Ask a Question