Posted on 9th February 2010One Response
How To Read Line By Line From Unix Shell(bash)?
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?
Comments
Leave a Response
Posted on February 9, 2010 at 1:37 am
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]