根据新行将列转置为行
Transpose column into row based on the new line
我有这样的文件
d
e
e
s
k
a
b
c
d
我只需要像这样转换就可以了
dee
sk
abcd
为此我使用了 awk 和 xargs
xargs < file|awk '{ gsub (" ", "", [=12=]); print}'
但它没有产生预期的结果
$ awk -v RS= -v OFS='' '{=}1' file
dee
sk
abcd
能否请您尝试以下。
awk '
!NF && value{
print value
value=""
next
}
NF{
value=value [=10=]
}
END{
if(value){
print value
}
}' Input_file
使用perl:
perl -0pe 's/\n(?=.)//g' file
输出
dee
sk
abcd
perl -l -00pe 'y/\n//d' file
-00
类似于 awk -v RS=
我有这样的文件
d
e
e
s
k
a
b
c
d
我只需要像这样转换就可以了
dee
sk
abcd
为此我使用了 awk 和 xargs
xargs < file|awk '{ gsub (" ", "", [=12=]); print}'
但它没有产生预期的结果
$ awk -v RS= -v OFS='' '{=}1' file
dee
sk
abcd
能否请您尝试以下。
awk '
!NF && value{
print value
value=""
next
}
NF{
value=value [=10=]
}
END{
if(value){
print value
}
}' Input_file
使用perl:
perl -0pe 's/\n(?=.)//g' file
输出
dee
sk
abcd
perl -l -00pe 'y/\n//d' file
-00
类似于 awk -v RS=