Domolith

Its Domorific!
  • rss
  • Home

Read File line by line with Shell Script (bash)

March 28, 2007 | 4:29 pm

I realize this is a very basic issue, but when searching online I found a dearth of information regarding reading a text file line by line using a shell script. So below I have included the basic code you need.


#!/bin/bash
#skeleton code for reading a file line by line

#fill variable “thefile” with the name and path of the file you want to read line by line
thefile=/home/var/nameoffileyouwanttoprocess

# the loop below pipes the output of the file into a variable ($line) line by line
cat $thefile | while read line
do
echo $line #placeholder command to make sure everything is groovy
done

Hopefully this helps some people!

Comments
6 Comments »
Categories
Bash, Shell-Scripts
Comments rss Comments rss
Trackback Trackback

Navigation

  • Bash
  • Facebook
  • Free
  • Open-Source
  • Reviews
  • Screencasts
  • Shell-Scripts
  • Software
  • StumbleUpon
  • Tutorials

Search

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox