My output looks like this:

 /map1/firmware1   Targets   Properties
     date=Jul 19 2016
     name=iLO 4

My desired output is:

version=2.44 date=Jul_19_2016

To merge the output into one line I tried to use xargs. But then he only prints date.

cat test | egrep '(version=|date=)' |xargs
 date=Jul 19 2016

OP's issue seems to be due to dos style line endings...


$ cat -e chk 
 /map1/firmware1   Targets   Properties^M$
     date=Jul 19 2016^M$
     name=iLO 4^M$

$ egrep '(version=|date=)' chk | xargs
 date=Jul 19 2016

After converting to unix style line ending:

$ perl -i -pe 's|\r\n|\n|' chk 

$ cat -e chk 
 /map1/firmware1   Targets   Properties$
     date=Jul 19 2016$
     name=iLO 4$

$ egrep '(version=|date=)' chk | xargs
version=2.44 date=Jul 19 2016
  • paste leads also to the missing version egrep '(version=|date=)' test |paste - - date=Jul 19 2016 – M.S. Sep 16 '16 at 7:54
  • what is the output of file test ? does it have CRLF line terminators? – Sundeep Sep 16 '16 at 7:58
  • file test test: ascii text But I think you are right and there are diffrent line terminators. The output comes directly from an HP ILO – M.S. Sep 16 '16 at 8:02

using sed one-liner

$ sed -n '/version/ {N; s/[\r\n]//g; p}' filename
     version=2.44     date=Jul 19 2016


  • /version/ matches pattern and executes the brace block { }.
  • N takes next line from input file and appends it to pattern space.
  • s/[\r\n]//g removes all newlines and carriage returns from pattern space.
  • p prints pattern space.
  • This works "half" :) I think that the output format will be the same over multiple servers, so I guess its okay to use "print next line after match". But I still want to swap the spaces in "date=Jul 19 2016" with _ – M.S. Sep 16 '16 at 7:58

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.