1

I am using sed within a while loop to remove the trailing blank spaces from a file containing a list of files. The blank spaces are being removed. But I'm getting the message sed:no input files.

Following is the while loop I am using:

while IFS= read -r line; 
        do
            echo "tester: $line"
            sed -i 's/\s*$//' $line ;
        done < file_list.txt

2 Answers2

2

As Ipor and glenn have both said, based on your report from B Layer's comment regarding tail -1 file_list.txt, since there is a blank line at the end of that file, when the while loop reads that blank line, the $line variable gets assigned an empty value, leaving no filename for sed to process.

$ cat i
file1
file2

$ while IFS= read -r line; do printf -- "-->%s<--\n" "$line"; done < i
-->file1<--
-->file2<--
--><--

The fix here is to delete that trailing blank line from file_list.txt, or wrap a test around your actual processing to test for the existence of the file:

# do ...
if [ -f "$line" ]
then
  # process file
fi
# done ...

and always quote your variables!

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
0

Had same issue, for me it was because I did not pass the input file to sed CMD

Example:

boy=$1
boy2=$2
boy3=$3
while IFS="," read -r col1 col2
do
 if [ "$col1" == "oke" ]; then

    sed -i "s/$col2/$boy/g" test.txt
  fi
done < test.txt