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



Comments

Popular posts from this blog

Configure, Modify, Rename,Delete a listener for Oracle 11g database

Oracle DB:Oracle 12C DB installation Error -Failed to access the temporary location

OSB : DB Adapter-Poll - Delete Logical Records using Oracle Service Bus 12c