How to use a dynamic filename with sed?

I have a line that works for static filename

cat /directorypath/filename | sed '/[text pattern1]/d;/[text pattern2]/d' > filename

This approach when used in a script works well.

Then i need a list of filenames to give this line.

I can get the list into a file by

filelist1='ls -m'

then use

filelist2=${filelist1##ls -m}
echo $filelist2 > mylist

This will create a list of filenames.
This line will print each

awk '{ for (i = 1; i <=NF; i++) print$i }' mylist

I figured it would be easy to sub the print$i with my cat / sed line using $i as the filename.

This is SFU on a windows box.

any help from the experts out there?

How about:

for FILE in /directorypath/*; do
  cat ${FILE} | sed '/[text pattern1]/d;/[text pattern2]/d' > `basename ${FILE}`
done

?

Thanks for your suggestion, what I am looking for now is to loop through the list.

I have just modified the code to:

cat $filename2 | sed '/Email/d;/Web/d' > temp.1
mv temp.1 $filename2

This works for one file.

I was looking for a way to handle errors (what if it runs and has no files?)
and what if more than one files comes in?

As mentioned, I can create a file that has the list.

---------- Post updated at 04:16 PM ---------- Previous update was at 04:08 PM ----------

Hi,

I tried the FILE code with multiple files

the message I got back was;
/bin/fix2.sh[3]: FILE: not found and it keep the editor open needed to ctrl 'c' to get prompt back.

Is the code you suggested exactly what I should type? or is FILE something I needed to change?

I am very new to this scripting.

The following is an example of reading in a list of files from a file:

while read FILE; do
  echo FILE = $FILE
done < file_list

Hi Tony,

thank you for your reply.

I have it working now.

What I figured out was I should have used Korn Shell not Bash.

SFU uses the Korn shell and once I figured that out I redid my script and it is working.

Thanks again

This post can be closed