1

I'm new to linux and don't know how to solve my issue. I have an output like this (about 200 lines):

Peter Griffin
222
Vasya Pupkin
333

I need to convert this to:

222, Peter Griffin
333, Vasya Pupkin

I tried

ldapsearch -LLL -D $bindDN -w $password -p $port -h $host -b $searchBase -S "telephoneNumber" -s sub cn telephoneNumber | grep -v "dn: " | grep "\\n" | awk -F": " '{ print $2 }'

How can I realize it?

Inian
  • 80,270
  • 14
  • 142
  • 161
Googlom
  • 25
  • 3

2 Answers2

1
xargs -L2 < inputfile|awk '{x=$NF;$NF=""; print x "," $0 }'
222,Peter Griffin
333,Vasya Pupkin

Explanation: xargs -L2 is to combine two consecutive lines into one. Once the input is changed to single line , feed it to awk for column manipulation.

Awk alone solution:

awk 'NR%2{x=$0;next} {print $0,",",x}' inputfile
P....
  • 17,421
  • 2
  • 32
  • 52
1

It can be done in Awk alone,

awk '{getline nextLine; print nextLine,$0}' OFS="," file
222,Peter Griffin
333,Vasya Pupkin

So with your commands, just pipeline the output that produces those lines to the Awk above,

.. | awk '{getline nextLine; print nextLine,$0}' OFS=","
Inian
  • 80,270
  • 14
  • 142
  • 161