AWK: convert row to column
3 answers
You can set the field separator to an empty string so that each character is a different field. Then loop through them and type:
$ awk -v FS="" '{for (i=1;i<=NF;i++) print $i}' <<< "abcdef"
a
b
c
d
e
f
Which is equivalent :
awk -F "" '{for (i=1;i<=NF;i++) print $i}' <<< "abcdef"
+2
source to share
Works only with internal awks variables:
echo abcdef | awk 'BEGIN{FS="";OFS="\n"}{$1=$1}1'
It sets the input fields delimiter ( FS
) to nothing, which means each character is a field. The output field separator ( OFS
) is set to a new line. Please note: $1=$1
it is necessary to restore a recording with a new one OFS
.
0
source to share