ZenMac
ZenMac

Reputation: 259

Transpose column into row based on the new line

I have file like this

d
e
e

s
k

a
b
c
d

I just need to convert then as like this

dee
sk
abcd

For this purpose I used awk and xargs

xargs < file|awk '{ gsub (" ", "", $0); print}'

But it is not generating results as expected

Upvotes: 3

Views: 244

Answers (4)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185254

Using :

perl -0pe 's/\n(?=.)//g' file

Output

dee
sk
abcd

Upvotes: 3

user13822462
user13822462

Reputation:

perl -l -00pe 'y/\n//d' file

-00 is similar to awk -v RS=

Upvotes: 2

karakfa
karakfa

Reputation: 67507

$ awk -v RS= -v OFS='' '{$1=$1}1' file

dee
sk
abcd

Upvotes: 5

RavinderSingh13
RavinderSingh13

Reputation: 133538

Could you please try following.

awk '
!NF && value{
  print value
  value=""
  next
}
NF{
  value=value $0
}
END{
  if(value){
     print value
  }
}' Input_file

Upvotes: 3

Related Questions