Linux Commands-paste, cut :Convert data in a text file from rows to columns
Sample file: input.txt
qw er ty
as df gh
zx cv bn
Step1:
Count the number of lines in the file using wc
count=`cat input.txt |wc -l`
Step2:
In a for loop based on above count variable, cut the values based on space and paste
for ((i=1;i<=$count;i++));
do
cut -d' ' -f"$i" input.txt |paste -sd' ';
done
Output:
qw as zx
er df cv
ty gh bn
qw er ty
as df gh
zx cv bn
Step1:
Count the number of lines in the file using wc
count=`cat input.txt |wc -l`
Step2:
In a for loop based on above count variable, cut the values based on space and paste
for ((i=1;i<=$count;i++));
do
cut -d' ' -f"$i" input.txt |paste -sd' ';
done
Output:
qw as zx
er df cv
ty gh bn
Comments
Post a Comment