How To Read Line By Line From Unix Shell(bash)?

Filed in Questions  |  
Tags: , , , , , , , ,
TOP del.icio.us digg

I have a file named abcd.txt. I want to read that file using BASH one line at a time. I tried using CAT but it just displays whole file. How to read it?

One Comment

  1. Comment by absolt12:

    The bash command “read ” will take a single line from stdin and place into the variable . Combine this with a while look to loop over the entire file.
    Your final script may look something like this:
    #!/bin/bash
    while read data; do
    echo $data;
    done
    This script will just echo every input line, but you can put more interesting things into the body of the loop. For more info look at [1]

Trackbacks / Pingbacks

Leave a Reply

Improve the web with Nofollow Reciprocity.