2

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, \

   jd,er,ew,yu,tg,ed,ik,cs,\

    mz,fg,jh

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. – Valentin Bajrami Feb 27 '17 at 20:45
-1

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 '17 at 21:38
  • awk '{gsub("host","");gsub("=","");print;}' filename____ this Worked Thank you, it is very appreciated – Moez Feb 27 '17 at 22:28
4

You could do:

 sed '
   # delete all but lines starting with host= (allowing blanks)
   /^[[:blank:]]*host[[:blank:]]*=[[:blank:]]*/!d

   # remove that host= part
   s///
   :1
   /\\$/{
     # if the line ends in \, append the next line and loop 
     N;b1
   }'

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.