B
B
BelBES2014-12-26 15:43:25
linux
BelBES, 2014-12-26 15:43:25

How to split console output into lines in Shell?

Hello!
The question is as follows. I have a Shell script, inside of which grep is done by files in the directory, I need to put the output of grep into a variable line by line. If I do something like this:

qqq=`grep nIHR 'PATTERN' file`
for q in qqq
do
   echo $q
done

Then grep's output will be printed to the console, where the entire log is hacked by words, which is not convenient. Can anyone suggest a way how to get split by lines? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
3
3vi1_0n3, 2014-12-26
@BelBES

Use IFS:

qqq=`grep -nIHR 'offset' ./file.dat`
IFS='
'
for q in $qqq
do
   echo $q
done

E
Exik, 2015-01-03
@Exik

while read line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question