Operating System - HP-UX
1838634 Members
2126 Online
110128 Solutions
New Discussion

Re: find a bad character in a script

 
SOLVED
Go to solution
Smucker
Regular Advisor

find a bad character in a script

We have a script that is having issues the following is happening

for EMPTY_FILE in `ls |grep '^EDI204'`
do
if [ ! -s ${EMPTY_FILE} ]

In the above code the directory listing is being cated together. In other words the the $EMPTY_FILE variable has all files in it instead of a single entry. I suspect a bad non-printable Character is somewhere in the script causing issues.

Any ideas on how to find the rogue character?
6 REPLIES 6
spex
Honored Contributor
Solution

Re: find a bad character in a script

Hi,

for EMPTY_FILE in `ls -1 EDI204*`
do
if [ ! -s ${EMPTY_FILE} ]
...

PCS
Kofi ARTHIABAH
Honored Contributor

Re: find a bad character in a script

Hi:

You ls will list a bunch of files on the same line (unless you have an alias for ls to be ls -1) since that may not be the case, modify your code to say:


for EMPTY_FILE in `ls -1 |grep '^EDI204'`
do
if [ ! -s ${EMPTY_FILE} ]

etc.

note: the -1 parameter causes every entry to be listed on a line of its own. Hope this helps.

Kofi
nothing wrong with me that a few lines of code cannot fix!
Smucker
Regular Advisor

Re: find a bad character in a script

The funny this is when I put in an echo (see below) it worked fine.

for EMPTY_FILE in `ls | grep '^ADD204'`
do
echo "this is empty file $EMPTY_FILE This is the end"
if [ ! -s ${EMPTY_FILE} ]
then


can you explain this
KapilRaj
Honored Contributor

Re: find a bad character in a script

I think folks have given you solutions. Let me add some value. I think the following code will save you some cpu cycles ;).

find ${dir_name} -name "EDI204*" -xdev -size 0 -exec #Add what you want to do to these files

** Or you may use | while read line and do what you want to do ..

Please note that 'find' will do down to the subdirectories too.

I am on an aix machine so please check the syntax of 'find' from manpages on an hpux machine. I don't think they are diffrent but it is always good to.

Regards,

Kaps
Nothing is impossible
KapilRaj
Honored Contributor

Re: find a bad character in a script

I hope it is not a typo "ADD" and "EDI"
Nothing is impossible
Smucker
Regular Advisor

Re: find a bad character in a script

thanks for all the suggestions. I passed it along