Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep file and save whole line into variable

Tags:

grep

unix

I'm trying to simply grep lines in a file. If the line has the word "status" in it, I need to parse it out and do things with it inside of my for loop. The problem is that there are spaces inside the line, so I'm only getting one word at a time. This loop is actually nested inside of another for loop, which is only reading certain files in my directory. I need to know how to read the whole line, with spaces and everything.

    for STATUS in `grep status $FILE`
        do 
           #do stuff
        done
like image 397
Mark Avatar asked Sep 01 '25 18:09

Mark


1 Answers

grep status $FILE | while read line; do
    echo $line ## or do whatever with it
done
like image 159
Costi Ciudatu Avatar answered Sep 05 '25 09:09

Costi Ciudatu