Appending the contents of two files in computational manner

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Appending the contents of two files in computational manner
# 1  
Old 04-06-2010
Appending the contents of two files in computational manner

Hi,

I have two files say file 1 file 2
File1
Code:
1
2
4
5

File 2
Code:
asdf
adf

How to get the ouput something like
Code:
asdf1
adf1
asdf2
adf2
asdf4
adf4
asdf5
adf5

Please give your comments

Last edited by vgersh99; 04-06-2010 at 11:24 AM.. Reason: code tags, please!
# 2  
Old 04-06-2010
one way:

Code:
#  while read a; do nawk -v a=$a '{print $0a}' file2; done < file1
asdf1
adf1
asdf2
adf2
asdf4
adf4
asdf5
adf5

# 3  
Old 04-06-2010
Code:
nawk 'FNR==NR{f2[FNR]=$0;next}{for(i=1;i in f2;i++) print f2[i] $0}' file2 file1

# 4  
Old 04-12-2010
MySQL

Hope this perl code will help
make sure you dont have any blank lines in the file1 and file2
Code:
use strict;
use warnings;

my @a = `cat file1 `;
my @b = `cat file2 `;

foreach my $c (@a )
{
    foreach my $d (@b)
    {
        chomp $c ;
        chomp $d ;
        print "${d}${c}\n";
    }
}

:b:
# 5  
Old 04-24-2010
You can use the below code

Code:
 
for i in `cat file1`
do
for j in `cat file2`
do
echo "$j$i"
done
done

Thanks
# 6  
Old 04-24-2010
Code:
while read i; do
  while read j; do
    echo "$j$i"
  done < file2
done < file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for %computational memory & % non computational memory

Dear, How to calculate %computational memory and %non computational memory from AIX server. What command used to find out %computational memory and % non computational memory except topas. Regards Nowshath (1 Reply)
Discussion started by: Nowshath
1 Replies

2. Shell Programming and Scripting

Capturing computational/non computational memory from topas

Hi Friends, How to capture the value of %Comp and %Noncomp values from AIX using topas command. I tried lot, but i cannot capture the value. (4 Replies)
Discussion started by: Nowshath
4 Replies

3. UNIX for Advanced & Expert Users

Appending a files contents to the end of a specific file name in several directories

Here is my dir structure: /tmp/dave/myappend.txt /tmp/dave/dir1/test.txt /tmp/dave/dir2/test.txt /tmp/dave/dir3/test.txt /tmp/dave/dir4/test.txt I want to append the contents of myappend.txt to the end of each file with the name "test.txt" in all dirs in /tmp/dave/ I have tried this:... (2 Replies)
Discussion started by: bigd213
2 Replies

4. Shell Programming and Scripting

How to sort and compare files in more efficient manner?

Hello All, Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file. sort -o temp.txt file1 mv temp.txt file1 sort -o temp.txt file2 mv temp.txt file2 sort -o temp.txt... (6 Replies)
Discussion started by: Vikram_Tanwar12
6 Replies

5. Cybersecurity

Computational complexity

This is a general question about the practical use of computational complexity in security. Wikipedia has a good article about the theoretical background of computational complexity. In the course of conversation with colleagues, a topic that is brought up occassionally is the security of any... (2 Replies)
Discussion started by: gratuitous_arp
2 Replies

6. Shell Programming and Scripting

Appending two files vertically

Hi Need ur help for the below question. I have two files File-1 & File-2. File-1(This is a fixed file i.e. the content of this file is not going to change over a period of time) ------ a b c d e File-2 (This is a file which changes daily but the record count remains the same)... (1 Reply)
Discussion started by: 46019
1 Replies

7. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

8. UNIX for Dummies Questions & Answers

Appending the two files

hi, I want to append to two files into a third file without new line like this: file 1: I am learning the unix file 2: Unix is very intersting When I am trying cat file1 file2 >> file3 I am getting: I am learning the unix Unix is very interesting But I want that to be in... (3 Replies)
Discussion started by: harish409
3 Replies

9. Shell Programming and Scripting

Reading specific contents from a file and appending it to another file

Hi, I need to write a shell script (ksh) to read contents starting at a specific location from one file and append the contents at specific location in another file. Please find below the contents of the source file that I need to read the contents from, File 1 -----# more... (5 Replies)
Discussion started by: dnicky
5 Replies

10. UNIX for Dummies Questions & Answers

appending files

I have 25 transaction files that need to be put into one file and have the date of the file appended at the end of the line, anyone got a one liner or simple script to help me out thanks - Ed (4 Replies)
Discussion started by: edog
4 Replies
Login or Register to Ask a Question