Re: for loop example

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



There's probably a better way using join, but this should do the trick:

paste <(cat file1 | tr "\n" ' ') <(cat file2 | tr "\n" " ")


On Tue, 07 Jun 2016 12:19:14 +0000
Diego <diegofull@xxxxxxxxx> wrote:

> Maybe this don't to be the best form to solve your problem, but worked,rs.
> 
> #!/bin/bash
> #power by Diego Rodrigues
> 
> totalFileOne=$(wc -l file1 | cut -d" " -f1)
> totalFileTwo=$(wc -l file2 | cut -d" " -f1)
> 
> count=0
> 
> if [ ! "${totalFileOne}" -eq "${totalFileTwo}" ];then
>     echo "The two files need of same number of lines"
>     exit 1
> fi
> 
> 
> for ((i=0;$i<${totalFileOne};i++));
> do
>     #add more one to some
>     NumberLine=$(( $i+1 ))
>     echo -en $(sed ${NumberLine}'!d' file1 ;sed ${NumberLine}'!d' file2)"\n"
> done
> 
> 
> Em ter, 7 de jun de 2016 às 08:42, <centos-request@xxxxxxxxxx> escreveu:
> 
> > Send CentOS mailing list submissions to
> >         centos@xxxxxxxxxx
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >         https://lists.centos.org/mailman/listinfo/centos
> > or, via email, send a message with subject or body 'help' to
> >         centos-request@xxxxxxxxxx
> >
> > You can reach the person managing the list at
> >         centos-owner@xxxxxxxxxx
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of CentOS digest..."
> >
> >
> > Today's Topics:
> >
> >    1. for loop example (Indunil Jayasooriya)
> >    2. remote backup (Alessandro Baggi)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Sat, 4 Jun 2016 11:11:21 +0530
> > From: Indunil Jayasooriya <indunil75@xxxxxxxxx>
> > To: CentOS mailing list <centos@xxxxxxxxxx>
> > Subject:  for loop example
> > Message-ID:
> >         <CAJF2yJSdCEysBoqGo2B+BerpgPYBmMxD=ahj4LiHN6xR8H=
> > 3Gg@xxxxxxxxxxxxxx>
> > Content-Type: text/plain; charset=UTF-8
> >
> > Hi list,
> >
> > Can you look in to this?
> >
> >
> > [root@centos67 loop]# cat file1
> > firstname1
> > firstname2
> >
> > [root@centos67 loop]# cat file2
> > lastname1
> > lastname2
> >
> > I need a OUTPUT like this
> >
> >
> > *firstname1 lastname1firstname2 lastname2*
> >
> >
> > But I try the below command , i get below output.  what is the real command
> > to get the above output
> >
> > [root@centos67 loop]# for line1 in $(cat file1 ); do for line2 in $(cat
> > file2 ); do echo "$line1" "$line2";done;done;
> > firstname1 lastname1
> > firstname1 lastname2
> > firstname2 lastname1
> > firstname2 lastname2
> >
> >
> > And also, I created a file3 like this
> >
> > [root@centos67 loop]# cat file3
> > firstname1 lastname1
> > firstname2 lastname2
> >
> > How can I get the same OUTPUT ?
> >
> >
> > *firstname1 lastname1firstname2 lastname2*
> >
> >
> > if I try below command, i get the below output.
> >
> > [root@centos67 loop]# for i in $(cat file3);do echo $i;done;
> > firstname1
> > lastname1
> > firstname2
> > lastname2
> >
> >
> > Could you pls help me to solve this ? THIS is very important to me.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > cat /etc/motd
> >
> > Thank you
> > Indunil Jayasooriya
> > http://www.theravadanet.net/
> > http://www.siyabas.lk/sinhala_how_to_install.html   -  Download Sinhala
> > Fonts
> >
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Sat, 4 Jun 2016 12:34:40 +0200
> > From: Alessandro Baggi <alessandro.baggi@xxxxxxxxx>
> > To: CentOS <centos@xxxxxxxxxx>
> > Subject:  remote backup
> > Message-ID: <5752AEC0.4010609@xxxxxxxxx>
> > Content-Type: text/plain; charset=iso-8859-15; format=flowed
> >
> > Hi list,
> > i've need to backup a partition of ~200GB with a local connection of 8/2
> > mbps.
> >
> > Tool like bacula, amanda can't help me due to low bandwidth in local
> > server.
> >
> > I'm thinking rsync will be a good choice.
> >
> > What do you think about?
> >
> > Thanks in advance.
> >
> >
> > ------------------------------
> >
> > _______________________________________________
> > CentOS mailing list
> > CentOS@xxxxxxxxxx
> > https://lists.centos.org/mailman/listinfo/centos
> >
> >
> > End of CentOS Digest, Vol 137, Issue 5
> > **************************************
> >
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxx
> https://lists.centos.org/mailman/listinfo/centos
> Total Control Panel
> https://asp.reflexion.net/history-detail?hID=15258593501



-- 
Nothing Whitty
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux