Re: OT: a problem about text manipulation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/31/06, Hirofumi Saito <hi_saito@xxxxxxxxxxxx> wrote:
> >I am looking for an automatic way of transforming my text file into
> >another one with the format
> You may try this:
>  cat ./test.txt | awk '{print $1" "$2; print $1" "$3; print $1" "$4}' |
>  grep -v ' $'

$ awk '{for(i=2;i<=NF;i++)printf $1"\t"$i"\n"}' test.txt

That's all.

or, try this.

$ awk '{for(i=2;i<=NF;i++)print $1, $i}' test.txt

I think awk is the best solution for this problem.

The following command does almost exactly what I want:

cat ./filename_introduced_user.txt | awk '{print $1" "$2; print $1"
"$3; print $1" "$4; print $1" "$5; print $1" "$6; print $1" "$7; print
$1" "$8; print $1" "$9; print $1" "$10; print $1" "$11; print $1"
"$12; print $1" "$13; print $1" "$14; print $1" "$15; print $1" "$16;
print $1" "$17; print $1" "$18; print $1" "$19; print $1" "$20; print
$1" "$21; print $1" "$22; print $1" "$23; print $1" "$24; print $1"
"$25; print $1" "$26; print $1" "$27}' | grep -v ' $' >
another_filename_introduced_user.txt

I am wondering whether it is possible to write a script to do the same
but for a number of columns introduced by the user.

Thanks in advance,

Paul


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux