• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6257
  • Last Modified:

BASH - read each line of text file to create a new one.

I have a BASH script that creates a directory of the current date, downloads files via psftp into that current date directory, then creates a text file of the list of files in that current date directory via this command:

ls *.bak > $DATE.list

My $DATE. list text file, for example 20071012.list, looks like this:

Now what I need to do is create another text file called $DATE.del which will add the command 'del' to the beginning of each like in the 20071012.list file and place 'quit' at the last line, for example 20071012.del would look like this:
del 20070928-accept.txt
del 20070927-accept.txt
del 20070928-beyond.txt
del 20070925-moved.txt

This has pushed my knowledge of BASH to its limit and I would appreciate any direction on this script.
1 Solution
while read f ; do  echo del $f ; done < $DATE.list >$DATE.del
echo quit >> $DATE.del

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now