Moving Content from one file to another with variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving Content from one file to another with variables
# 1  
Old 01-27-2010
Moving Content from one file to another with variables

Greetings All,

Need some help, your input is appreciated.

Scenario:
I have five files, each has one line with comletely different content. I execute the command to combine all the five lines of content into a single file.

Goal:
I would like to take that single file that has the combined five lines in it and make those five lines a single variable that can then be passed along and used as content within a mailx command.

Any suggestions?
# 2  
Old 01-27-2010
Code:
cat file1 file2 file3 file4 file5 > outfile
var=$(cat outfile)

or if you want to skip creating the new file:

Code:
var=$(cat file1 file2 file3 file4 file5)

# 3  
Old 01-27-2010
Code:
var=${head -1 file1 file2 file3 file4 file5}

# 4  
Old 01-27-2010
Thanks all; that works, but it puts the content on a single line, what if i wanted it to continue down a single column (new line).

file1
a
b
c

file2
d
e
f

var=`cat file1 file2`
echo $var

DESIRED RESULTS: fileX
a
b
c
d
e
f

Feedback?

---------- Post updated at 09:16 AM ---------- Previous update was at 08:56 AM ----------

NEVERMIND! LOL;

I was viewing it wrong. It does it properly; thank you all. Solution works.

v/r
Roy Arellano
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for moving one file with date content in name

Dear All, I am having a database that generates daily backup files in the below format. abc_date_0010.zip. Can you please suggest a method to copy the last day's file to another location. I am trying with if statement, but having difficulty while I use the condition like if ; then ... (4 Replies)
Discussion started by: skooby
4 Replies

2. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

3. Shell Programming and Scripting

Moving files from one directory to another based on 2 date variables

Hi All, I am currently coding for a requirement(LINUX OS) where I am supposed to move a file (Lets Call it Employee.txt) from Directory A to Directory B based on 2 date fields as below, Date_Current = 20120620 Date_Previous = 20120610 Source Directory : /iis_data/source Target... (11 Replies)
Discussion started by: dsfreddie
11 Replies

4. Shell Programming and Scripting

Comparing content of two variables

I have very abstract need of "comparing two variables" and take subsequent actions. please refer to image below https://lh3.googleusercontent.com/-frNk5iA3q1c/TjI3lE0sWOI/AAAAAAAAAIE/fxzB1w07gas/script_block.JPG I have a part of script which reads a file and generates variables based on... (4 Replies)
Discussion started by: animesharma
4 Replies

5. Shell Programming and Scripting

Help needed in perl; moving or copying the variables

Hi All, I have a perl script blc.pl; i have five variables a,b,c,d and e in this script. Now I want to copy the values of these variables into a data file,say abc.dat.. Can anybody please tell me how to do this? Any help is appreciated.. Thanks in advance (2 Replies)
Discussion started by: puneetkanchi
2 Replies

6. Shell Programming and Scripting

list file content as individual variables

Hello, I've created a couple of files within a list using the command "ls -ltr | tail -2 > list" These files are the newest files placed within a directory. From the "list" file, I need to place the filenames as a variable. In which the newest file will be called "new_ctrl" the older file... (4 Replies)
Discussion started by: petersf
4 Replies

7. Shell Programming and Scripting

moving variables to another variable as a new avriable

Somehow I can't get it for this basic bash problem. maybe someone can help. What I try to do is: a="world" b="hello" how can I move this into $c so that I can replace "helloworld" with "world hello" in sed like: sed "s/\helloworld/ ${c}... I tried several combinations but all with... (4 Replies)
Discussion started by: lowmaster
4 Replies

8. Shell Programming and Scripting

comparing content of 2 variables in script

hello how can i compare the content of two variables using the if or for loops. I have 2 variables which was formed as result of commands pass into them but i want to now compare the 2 contents and echo where their is a match for examples variable1=`cat file2` variable2=`cat file3` if #... (5 Replies)
Discussion started by: sam4now
5 Replies

9. Shell Programming and Scripting

file moving based on file content

Hi All my scenario is as follows... I have the following three files in directory alphabet, containing the respective character string... Filename Character String alphabet01.dat AAA alphabet02.dat BBB alphabet03.dat CCC based on... (12 Replies)
Discussion started by: melvyn.cochrane
12 Replies

10. Shell Programming and Scripting

Put content of file into variables

How to put a line of strings (with some white spaces in between) from a file into variables? I have tried the following codes. However, the content is cut by space (not by line) for i in `cat ${source_file}` do echo $i done Please comment. Thanks. (2 Replies)
Discussion started by: Rock
2 Replies
Login or Register to Ask a Question