Marius van Witzenburg We fight for our survival, we fight!

10Jul/110

How to read a file line by line with Bash

Sometimes you want to do actions per line instead of the complete file at once.

Here is an example that you can use to read the file line by line.

#!/bin/bash
run_cmd_file() {
    while read line
    do
        chr=${line:0:1}
        case $chr in 
            "#" )  # ignore commented lines
                ;;      
            *   )   
                echo line[$line]"
                ;;      
        esac    
    done < $2
}
 
run_cmd_file filename

Posted by mariusvw

Geëtiketeerd als: , , , , , Laat een reactie achter
Reacties (0) Trackbacks (0)

Nog geen reacties


Leave a comment

(required)

Nog geen trackbacks.