Mix two files line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mix two files line by line
# 1  
Old 11-15-2013
Mix two files line by line

I have a file "fruits" and one "colors"

File "colors" contains:
Code:
green
red

File "fruits" contains:
Code:
apple
banana

I want the output to show all possibilities of fruits and colors:
Code:
greenapple
greenbanana
redapple
redbanana

The order is not important, but I need all possibilites.

Any ideas?

Last edited by Scrutinizer; 11-15-2013 at 03:07 PM.. Reason: code tags
# 2  
Old 11-15-2013
What have you tried so far?
What language would you like to use?
What OS and version are you using?
Do you want a space between colours and fruit or not?

Mostly, what have you tried so far.



Sorry to be a little terse, but if you've tried something that you don't like, then tell us and it will stop us going the same way. You will get better responses for putting in some effort yourself first and explaining exactly where you are stuck.

It's easy to give you an answer (and there are lots of ways to get thing output you suggest), but then you will not be learning or we might give you something inappropriate to your other needs not listed.




Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 11-15-2013
Quote:
Originally Posted by rbatte1
What have you tried so far?
What language would you like to use?
What OS and version are you using?
Do you want a space between colours and fruit or not?

Mostly, what have you tried so far.



Sorry to be a little terse, but if you've tried something that you don't like, then tell us and it will stop us going the same way. You will get better responses for putting in some effort yourself first and explaining exactly where you are stuck.

It's easy to give you an answer (and there are lots of ways to get thing output you suggest), but then you will not be learning or we might give you something inappropriate to your other needs not listed.




Robin
Liverpool/Blackburn
UK
I have no idea where to start.

I could do a big shellscript to do it, but I believe there's something much simpler that I'm missing.
# 4  
Old 11-15-2013
Consider this logic:-
  • You want to read a file called colours
  • For each line it contains, you want to do the following
    • You want to read a file called fruits
    • For each line, you want to display the current colour followed by the current fruit

If you are in a shell script (ksh, bash, etc.) you need to have a loop to read in each file similar to this:-
Code:
while read variable
do
   some action
done < file

Other coding options will exist for awk, sed, perl, csh and the list goes on. This is why it would be good to know what you are starting with this issue. What are you experienced in? That's normally a good way to think about things.

Is this homework perhaps? If so, there is a homework forum.


Does that help? Would you like to experiment and let us know how you get on?




Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 5  
Old 11-16-2013
Moderator's Comments:
Mod Comment Removed

Last edited by Scott; 11-16-2013 at 08:28 PM.. Reason: ...
# 6  
Old 11-16-2013
Moderator's Comments:
Mod Comment Removed

Last edited by Scott; 11-16-2013 at 08:29 PM.. Reason: ...
This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 11-16-2013
If you see that a member is donating of their valuable time to teach someone how to solve their problem -- a process which requires some contribution from the one being helped and which is more likely to result in learning -- please don't undermine that effort by providing a complete, ready-made solution.

Regards,
Alister
These 5 Users Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

3. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

4. UNIX for Dummies Questions & Answers

Script to delete files line by line in .txt document

Friends, I am in need to delete files from a directory on a regular basis. I want to place all the files to be deleted in delete .txt file and require a script to delete files, line by line from this delete.txt file. Please help me with this script as am new to unix scripting. (3 Replies)
Discussion started by: fop4658
3 Replies

5. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

6. Shell Programming and Scripting

Faster Line by Line String/Date Comparison of 2 Files

Hello, I was wondering if anyone knows a faster way to search and compare strings and dates from 2 files? I'm currently using "for loop" but seems sluggish as i have to cycle through 10 directories with 10 files each containing thousands of lines. Given: -10 directories -10 files... (4 Replies)
Discussion started by: agentgrecko
4 Replies

7. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

8. Shell Programming and Scripting

linux shell script to take variables from two different files line by line

Friends I need to have a shell script which will feed variables from two different files line-by-line. For example, I have two files - permission and file_name. Contents of permission is - 644 755 .... contents of file_name /file1 /file2 ..... Now I want 644 permission will be... (4 Replies)
Discussion started by: atanubanerji
4 Replies

9. Shell Programming and Scripting

How to calculate mean in AWK? line by line several files, thousands of lines

I'm kinda stuck on this one, I have 7 files with 30.000 lines/file like this 050 0.023 0.504336 050 0.024 0.529521 050 0.025 0.538908 050 0.026 0.537035 I want to find the mean line by line of the third column from the files named like this: Stat-f-1.dat .... Stat-f-7.dat Stat-s-1.dat... (8 Replies)
Discussion started by: AriasFco
8 Replies

10. Shell Programming and Scripting

copying from line N1 to line N2 of a file in a series of files

Dear community, I'm quite a newbie with scripting, I have this problem: I have a file with many lines and I want to copy the lines from 1 to N to file.1, from N+1 to 2N to file.2, and so on up to the end of the file I have tried with something like this (N=43 in this example): awk '{for... (2 Replies)
Discussion started by: paolalup
2 Replies
Login or Register to Ask a Question