How To Read Line By Line From Unix Shell(bash)?
Filed in Questions |Tags: abcd, cat, File, From, line, Read, Shellbash, txt, Unix
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?



Tuesday, February 9th 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]