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

Posted on 2007-10-12
Last Modified: 2010-05-18
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.
Question by:atkinsonit
    1 Comment
    LVL 84

    Accepted Solution

    while read f ; do  echo del $f ; done < $DATE.list >$DATE.del
    echo quit >> $DATE.del

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now