I am trying to collect lines from a file with the specific word host: for example the word host, I need to get output of all names of hosts. This is my file:

host= mx,rt,fd,rt,wed,asd, \
      fm, jklf,dfd,dfd
host = jd,er,ew,yu,tg,ed,ik,cs,\
       fd, gr, jy
host = mz,fg,jh

I am using :

$grep -i host filename | awk '{print $2}'

only works for the first line , it does not output any name after \

so the output is;

   mx,rt,fd,rt,wed,asd, \



as you see I am not getting rest of the line after \

I don't want to get rid of \ I would like to keep it, I can move it and connect all names, so it will be seen as one_line , but I don't want to do that.

Any idea , it is appreciated, it could be easy , but I can make it work, even when I use tr.

  • 3
    Show what your input is and what output you want. The fact that nobody responds is that you should rephrase your question. Feb 27, 2017 at 20:45

2 Answers 2


You could do:

 sed '
   # delete all but lines starting with host= (allowing blanks)

   # remove that host= part
     # if the line ends in \, append the next line and loop 

Give this a shot awk '{gsub("host","");gsub("=","");print;}' filename

awk remove the host and = and then just print each line.

  • It's standard awk (awk '{print;}'). Just try it. I already did.
    – jiveturkey
    Feb 27, 2017 at 21:38
  • awk '{gsub("host","");gsub("=","");print;}' filename____ this Worked Thank you, it is very appreciated
    – Moez
    Feb 27, 2017 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.