using two variables in two different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using two variables in two different files
# 1  
Old 09-07-2011
using two variables in two different files

I have file1 contents as
Code:
aaa
bbb
ccc

file2 contents as
Code:
ddd
eee
fff

I need to write for loop with two variables, so that I get the output as follows.
I have a third file that contain following
Code:
aaa 111
bbb 111
ccc 111

I need to replace them as follows
Code:
aaa ddd
bbb eee
ccc fff

# 2  
Old 09-07-2011
I don't understand how that third file fits in, but you can simply paste the first two files to get the final result:
Code:
paste file1 file2

Regards,
Alister
# 3  
Old 09-08-2011
I try below
Code:
server 1# cat file1
aaa
bbb

server 1# cat file2
ccc
ddd

server 1# cat test.sh
#!/bin/bash
var=`paste file1 file2`
echo $var

server 1 # sh test.sh
aaa ccc bbb ddd

I need output as follows
Code:
aaa ccc
bbb ddd

# 4  
Old 09-08-2011
Code:
 
echo "$var"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store output in variables instead of files

Hi All, I have written a (bash) function which generates multiple files say file1 file2 file3 now I want to reduce the generation of these three files i.e. store the output of three files in variables, and generate the same results, in-order to avoid multiple creation of files how is that... (7 Replies)
Discussion started by: sam@sam
7 Replies

2. Shell Programming and Scripting

How to create files with two or more variables in its names?

Hi all, Iam writing a perl script to create many files with variables in their name. i am able to do it, if iam using only one variable. But with two variables the file names are NOT getting generated in the way i want. plz help me out. 1. open(SHW,">divw_unsigned_50_50_$k.reset") or die... (4 Replies)
Discussion started by: twistedpair
4 Replies

3. Shell Programming and Scripting

Modifying Variables in Files

hi list, I am currently looking to develop an installation script which writes out .conf files based on existing .conf files according to variables which are set in a settings file. For example I have a settings file like so: ip=192.168.1.1 hosts=localAnd I want to read a file which... (3 Replies)
Discussion started by: landossa
3 Replies

4. Shell Programming and Scripting

Problem renaming files using variables

Hi, I have the following problem: I have a list of files: 1.txt 2.txt 3.txt 4.txt Then I have a list of variable names inside variable.txt: A B C D I'd like to rename 1.txt, 2.txt etc using the variables from variable.txt (2 Replies)
Discussion started by: hubleo
2 Replies

5. OS X (Apple)

using variables when copying files

smaller sample from a larger script: i'm simply trying to copy files from one desktop directory on a mac to another using variables. when i first test the logic of the script without variables, everything works and the copy is effective. but i'm unable to call the same copy by passing a... (3 Replies)
Discussion started by: hungryd
3 Replies

6. UNIX for Dummies Questions & Answers

[Solved] take name of directory and files as variables

hi, want to create script that takes name of directory and all files and will copy each file to new directory. then fix errors like files do not exist or no permission to create new directory... these what I have so far... #!/bin/sh dir=~/Documents/Scripts/Copy for i in $(pwd) $(ls)... (23 Replies)
Discussion started by: me.
23 Replies

7. UNIX for Advanced & Expert Users

Renaming Multiple Files that have variables in the name

I am trying to rename multiple files from lower case to upper case, but then I need to change the word SHIP to Ship and CSV to csv. This is a sample of the input file name input_file_ship_1234_20110106.csv I need this to look like this INPUT_FILE_Ship_1234_20110106.csv this is the result when I... (3 Replies)
Discussion started by: cventura
3 Replies

8. Shell Programming and Scripting

Making 256 files with variables

Hi, I am really sorry for posting a newbie question here, but I do not have time to start learning shell scripting at the very moment. My question is how can I write a script what takes a file with a variable number, changes the variable number to a new number and saves the file as a new... (5 Replies)
Discussion started by: mario8eren
5 Replies

9. Shell Programming and Scripting

Filtering multiple files with variables

Hi, I spend few hours already searching this forum, but cannot find the solution matching exactly my case. I have multiple log files, I need to filter them so I get info about certain event. So we have files: LOGA.txt LOGB.txt LOGC.txt LOGD.txt LOGE.txt 1. I need to grep lines in... (10 Replies)
Discussion started by: Vitoriung
10 Replies

10. Shell Programming and Scripting

Substituting variables from external files

Hi All, I have the following problem: 1. I have a file containing a line: a,b,d,${d},e,f 2. From within a script I grep the file for '^a,' to get the line 3. I obtain the fourth field as follows: Field4="$( print -r $fileEntry | cut -d, -f4 )" 4. The script exports variables at the... (1 Reply)
Discussion started by: oneillc9
1 Replies
Login or Register to Ask a Question