≡ Menu

Shell Script Utility To Read a File Line By Line

{ 39 comments… add one }
  • Azaz February 8, 2012, 5:43 am

    Cool, I found this script very useful. I modified this and used to make our syncronisation across servers fully automated. Great Job

  • cavin November 10, 2011, 7:16 am

    THANK YOU for sharing the script..it’s very generous/kind sharing…THUMBS UP

  • anon August 23, 2011, 5:00 pm

    Don’t listen that fool Dedeepthi ↑
    Here is the real code:
    —–cut here—————
    for i in ‘cat file.txt’
    echo “$i”
    —–cut here—————

  • Dedeepthi March 31, 2011, 9:10 am

    You can try this simple code to read the file “file.txt” line-by-ine….

    while read line
    echo $line;
    sleep 1;
    done < file.txt

  • DIPANKAR GHOSH January 31, 2011, 12:53 pm

    hi i want to update a port number in a file such like……
    file content…..abc.cfg

    # Temporary use by Boyajian. Thank you.
    # Plz feel free to change as per ur need. Thnx – Ayan



    now if i want to update the value of ACE_MATCH_SERVER_PORT from 16711 to 78777
    what would be the code to do this stub? please give a solution at the earliest

  • CrackTheInterview January 21, 2011, 11:29 am

    for line in `cat abc.txt`;do
    touch path/$line

    this 2 line is code enuff

  • SK October 19, 2010, 8:07 am

    Hi Very informative post. Thanks for this.
    But I have one confussion that
    what following code is doing. Please healp.
    IFS=$(echo -en “\n\b”)
    exec 3<&0
    exec 0<"$FILE"

  • Vimarsh August 23, 2010, 10:16 am


    I need to read a file and see for the occurence /local/svncheckout/* at the begining of each line. If this instance is found I need to delete that particular line.

    I need to write this program using shell script (bash shell)

    Thanks a lot

  • sj July 9, 2010, 4:47 am

    I edited the code to input the contents of $line when ever the loop runs. it inputs line by line in a file that contains a list of id’s I pulled out of etc/passwd. for some reason it’s stops at the 25th line. it starts combining the variables to I dont’ know what’s going on. how it could work for the first 25 entries then break.

  • Samuel May 14, 2010, 8:31 pm

    Thanks for posting it!!!

  • Sanjay March 8, 2010, 2:50 pm

    Thank you for the post.
    It’s work perfectly but i need some changes
    can u help me?
    i want a search a specific pattern in a file and copy a a search result to xml file
    Thanks in advance.

  • vinu February 16, 2010, 6:55 pm

    This is not working for me.

    sh read.sh v1.txt
    : not found:
    : not found: }
    : not found:
    : not found:
    read.sh: 40: Syntax error: “elif” unexpected (expecting “then”)

  • Thushara December 29, 2009, 5:34 am

    Thank you for the post!!

  • ijo December 13, 2009, 5:47 pm


  • Hari October 28, 2009, 9:15 pm

    I have used your example countless time when i wanted to write a quick hack. Thank You!

Security: Are you a robot or human?

Leave a Comment