Getting Error in with cat command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting Error in with cat command
# 1  
Old 07-29-2014
Getting Error in with cat command

Hi All ,
Below is the script which I have written -

Code:
export LOGDIR=/home/rmsbatch/testdata


# TEMPDIR : Path where all non zero files need to be moved after search.
export TEMPDIR=/home/rmsbatch/testdata/TEMP

# RESULTFILE : Path of the Final File 
export RESULTFILE=${TEMPDIR}/belk_rpo_error.txt

###############################################################################
#                                     MAIN                                    #
###############################################################################
#set -x
if [ $# -ne 1 ]
  then
    echo "Please Provide Date range"
    echo "Example: ./belk_rpo_shell_script.ksh "
    exit 1
fi

DATE_RANGE=$1
echo $DATE_RANGE


cd $LOGDIR

if [ -f ValidFiles ];then
  rm -rf ValidFiles
fi

find . -name "*.log" -mtime -$DATE_RANGE | xargs ls -lt|awk -F" " '{print $9}'|sed 's/.\///' > FILE_LIST

while read fname
do
  PONUM=$(expr substr $fname 16 9)
  echo $PONUM

  find . -name "*.log" -mtime -$DATE_RANGE | xargs ls -lt |awk -F" " '{print $9}'|sed 's/.\///'|grep $PONUM |head -1|  
  while read fn
      do
        if [ -s ${fn} ]; then #Non Empty
            echo ${fn} >> ValidFiles
        fi

      done 
 done <FILE_LIST
# Remove Duplicate File Names
cat ValidFiles |uniq >tmp
cat tmp > ValidFiles

if test -f $RESULTFILE; then
  rm -rf $RESULTFILE;
fi

while read error_file
do
   cat $error_file >> $RESULTFILE
   mv  $error_file $TEMPDIR/$error_file
   

done < ValidFiles

cd $TEMPDIR
rm 

nawk '!x[$0]++' $RESULTFILE > temp
mv temp $RESULTFILE

sed '/@0PACKAGE_ERROR@1ORA/d' $RESULTFILE > temp
mv temp $RESULTFILE

Code:
find . -name "*.log" -mtime -$DATE_RANGE | xargs ls -lt|awk -F" " '{print $9}'|sed 's/.\///'

Gives a list of file names in the a list like sorted by date-
Code:
file_1
file_2
file_2

Now I am getting the error :
Code:
cat - can't read or open file ValidFiles

I cant seem to figure out where I am getting error.
Any help is very appreciated.
PS : OS- AIX

Last edited by rbatte1; 07-29-2014 at 01:12 PM.. Reason: Ad
# 2  
Old 07-29-2014
My first observation (after adding a few CODE tags) is that you remove the file ValidFiles after checking that it exists; then you start a loop which may or may not append to the file ValidFiles

If you do not write any records to ValidFiles then you will get the message you are seeing.
Perhaps you should test that it exists first before executing the cat ValidFiles | uniq > tmp line.

Can you trace the error by putting this in at a suitable point?:-
Code:
set -x

That will switch on tracing until you issue the reverse in the script, or the script ends.
Code:
set +x




Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 07-29-2014
Quote:
Originally Posted by rbatte1
My first observation (after adding a few CODE tags) is that you remove the file ValidFiles after checking that it exists; then you start a loop which may or may not append to the file ValidFiles

If you do not write any records to ValidFiles then you will get the message you are seeing.
Perhaps you should test that it exists first before executing the cat ValidFiles | uniq > tmp line.

Can you trace the error by putting this in at a suitable point?:-
Code:
set -x

That will switch on tracing until you issue the reverse in the script, or the script ends.
Code:
set +x


Robin
Hmm got your point. one quick question does set +x turns off tracing as opposed to set -x ?
# 4  
Old 07-29-2014
Yes, that is correct. Running this as a script will illustrate:-
Code:
printf "Hello Tonto!\n"
set -x
printf "Hello Tonto!\n"
set +x
printf "Hello Tonto!\n"

Code:
Hello Tonto!
++ printf 'Hello Tonto!\n'
Hello Tonto!
++ set +x
Hello Tonto!

If this does not show where your problem is, try to get the smallest reproduction you can with the set -x in place and paste the output in CODE tags so we can have another think.


Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help need on cat command

I have two files as below 1.txt AA 123 CC 145 DD 567 2.txt AA 111 YY 128 CC 144 FF 222 DD 777 ZZ 875 basically 1.txt is updated file, if i do cat 1.txt 2.txt output should be as below o/p (4 Replies)
Discussion started by: Tecnical_help12
4 Replies

2. Shell Programming and Scripting

Help need on cat command

I have two files as below 1.txt AA 123 CC 145 DD 567 2.txt AA 111 YY 128 CC 144 FF 222 DD 777 ZZ 875 basically 1.txt is updated file, if i do cat 1.txt 2.txt output should be as below o/p (2 Replies)
Discussion started by: Tecnical_help12
2 Replies

3. Shell Programming and Scripting

cat command error

I use the "cat" command to cancaterate files into a new file. Sometimes the cat command failed because there were too many files in the directory for cancateration. I also tried to use the "ls" command to put the list of files into a text file and then cancaterate each file one by one by... (6 Replies)
Discussion started by: lena keung
6 Replies

4. AIX

cat command

Hi. How can i write a command on AIX like the one i did at linux that find string in a file and show me that string, and return 3 lines before and 4 lines after that string. my linux command is: /bin/cat <filename> | tail -150 | grep -B2 -A8 "<string to look for>" Example: /bin/cat ... (10 Replies)
Discussion started by: yechi_r
10 Replies

5. Homework & Coursework Questions

Need some help on using cat command

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle... (1 Reply)
Discussion started by: ashok.g
1 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

7. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

8. UNIX for Dummies Questions & Answers

CAT command

All - how do i save the file after i used CAT command line to modify? Thanks :confused: (2 Replies)
Discussion started by: March_2007
2 Replies

9. Shell Programming and Scripting

cat command

What does the below command means $cat <<% >abc.txt (3 Replies)
Discussion started by: surjyap
3 Replies

10. Shell Programming and Scripting

the CAT command

hi everybody, how do i open a txt file writen in unix on to a web page so when i want to view the txt file that was generated from a shell program, that file is open on a web page do i use the cat > filename.html command to do this, or is there another way many thanks :D (2 Replies)
Discussion started by: alexd
2 Replies
Login or Register to Ask a Question