Brad Ellis
Brad Ellis

Reputation: 309

How do I close out a bash script without getting an unexpected end of file?

Trying desperately to write a script that will read through each line of text from a file

Determine if that line contains a single quotation mark, delete that quotation from the line

if more than 2 no action

create a new file with the edited lines and non-edited lines

I was expecting to run into some trouble with the way that I'm parsing, but I'm actually hitting an unexpected end of file error?

Can someone guide me on exiting or ending the read? I've searched the plethora of EOF topics and it just doesn't really make sense.

read -p "User file: " fileName
if [ ! -e $fileName ];
then
  echo ${fileName} doesn''t exist or is not a file
  exit 1
fi

# Check  |to see if it exists and throw and error if it doesn't
ls $fileName > /dev/null


cat $fileName 

while read line
count= 'grep " | wc -m' 
if [ "$count" < 2 ];
then
  $line | tr -d '"'

fi

echo  $filename >> newFile.csv

exit

Upvotes: 0

Views: 54

Answers (1)

Amit
Amit

Reputation: 20516

read -p "User file: " fileName
if [ ! -e $fileName ];
then
  echo ${fileName} doesn''t exist or is not a file
  exit 1
fi

# Check  |to see if it exists and throw and error if it doesn't
#ls $fileName > /dev/null   # No need for this, you already checked above

while read line
do
    count= 'grep " | wc -m' 
    if [ "$count" < 2 ];then
        $line | tr -d '"' >> newFile.csv  #write to new file if condition meets
    fi 
done < ${filename}   # read from file line by line

#echo  $filename >> newFile.csv #This would print only the filename in the newfile.csv

exit

Upvotes: 1

Related Questions