Hi list, Can you look in to this? [root at centos67 loop]# cat file1 firstname1 firstname2 [root at 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 at 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 at 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 at 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
On 6/3/2016 10:41 PM, Indunil Jayasooriya wrote:> I need a OUTPUT like this > > > *firstname1 lastname1firstname2 lastname2*An obvious solution is to use Perl. I suggest searching Stackoverflow for a solution using that language. While checking, I discovered the paste program does just what you want. So try "man paste".
On Sat, Jun 04, 2016 at 11:11:21AM +0530, Indunil Jayasooriya wrote:> Hi list, > > Can you look in to this? > > > [root at centos67 loop]# cat file1 > firstname1 > firstname2 > > [root at centos67 loop]# cat file2 > lastname1 > lastname2 > > I need a OUTPUT like this > > > *firstname1 lastname1firstname2 lastname2* >Assuming your files 1&2 will be longer than 2 lines, consider this: paste -d' ' file1 file2 | awk '(NR%2) == 1 {l1 = $0; getline ; print l1 $0}' -- Jon H. LaBadie jon at jgcomp.com 11226 South Shore Rd. (703) 787-0688 (H) Reston, VA 20190 (703) 935-6720 (C)
On Tue, Jun 7, 2016 at 5:33 PM, Kenneth Porter <shiva at sewingwitch.com> wrote:> On 6/3/2016 10:41 PM, Indunil Jayasooriya wrote: > >> I need a OUTPUT like this >> >> >> *firstname1 lastname1firstname2 lastname2* >> > > An obvious solution is to use Perl. I suggest searching Stackoverflow for > a solution using that language. >yeah, you are right. http://stackoverflow.com/questions/18909957/how-to-use-bash-script-to-loop-through-two-files #!/bin/bash paste file_in.txt file_out.txt | while read if of; do echo "-in $if -out $of" done my example. [root at centos67 loop]# cat file1 firstname1 firstname2 [root at centos67 loop]# cat file2 lastname1 lastname2 [root at centos67 loop]# paste file1 file2 | while read if of; do echo "$ if at example.com $of at example.com"; done firstname1 at example.com lastname1 at example.com firstname2 at example.com lastname2 at example.com thanks for your mail.