Re: OT: a problem about text manipulation

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

 



On Sat, 2006-11-04 at 09:33, Paul Smith wrote:
> 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,

If you want to adapt to the columns in the file, this
would work:

#!/bin/sh
while read LINE
do
 set -- $LINE
 N=$1
 while shift
 do
  if [ -n "$1" ]
  then
   echo $N $1
   fi
 done
done
                                                                                If you want to set a limit on the columns you could add a
counter on the loop doing the shift and pass a value in
on the command line.

-- 
 Les Mikesell
   lesmikesell@xxxxxxxxx


-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux