Put content of file into variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put content of file into variables
# 1  
Old 11-30-2006
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  
Old 11-30-2006
IFS=""
for i in `cat ${source_file}`
do
echo $i
done

John Arackal
# 3  
Old 12-01-2006
Here is a solution without changing the IFS and getting rid of UUOC.

Code:
while read line
do
  echo "$line"
done < ${source_file}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prevent content of variables from showing in ps

system OS: ubuntu, redhat shell: /bin/sh i noticed that if im running a script and i go to a separate terminal and type: ps -efauxx | egrep "<the-script-name>" i see that the content of all the variables in the script are all visible. How can i avoid/prevent this? the scripts in... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

How to put variables commands in config files?

Hi All, Seeking for your assistance on how to put in variables all the commands in /bin config files: /home/test/config_file/config.cfg cat /home/test/config_file/config.cfg ECHO=/bin/echo LS=/bin/lsMain script cat test.sh source=/home/test/config_file/config.cfg ECHO=$ECHO LS=$LS#i... (3 Replies)
Discussion started by: znesotomayor
3 Replies

3. 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

4. Shell Programming and Scripting

How to put content of file into a variable?

For example, I have a simple text file note: this a note a simple note a very very simple notewhen I use this command, temp=$(cat "note.txt")then I echo temp, the result is in one line. echo $temp note: this a note a simple note a very very simple noteMy variable doesn't have newline. How... (7 Replies)
Discussion started by: 14th
7 Replies

5. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: royarellano
3 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

Ways to put variables into zenity radiolist

Hey guys, i have got a problem...zenity is not being able to read my variables in its radiolist options. as zenity needs a FALSE in front of a radiolist options, i have decided to ... op=$(awk '{print "FALSE" " " $2} /etc/fstab) $?=$(zenity --list --text "mount" --radiolist --column... (1 Reply)
Discussion started by: dplate07
1 Replies

8. Shell Programming and Scripting

put value of multiple sql statements into unix variables

i want to use multple sql count statements and store these count values in unix variable but in one connection only i.e. in only 1 time database should be hit ,which is the main requirement. (1 Reply)
Discussion started by: sw@pnil
1 Replies

9. Shell Programming and Scripting

How to read a line and put it into 3 variables

Hi All, I'll get a file whose 2nd line contains 3 fields: filename(variable length), file size char(10), and record count int(10). How do I cut it and put it into 3 variables? eg: abcd.csv01234567891111111111 now I want: $one = abcd.csv, $two = 0123456789, $three = 1111111111. I also... (8 Replies)
Discussion started by: Mandab
8 Replies

10. UNIX for Dummies Questions & Answers

How can I put wildcards in an if statement that uses variables?

With the if statement: if How can I make it so it accepts a wildcard after the ${CURR_DAY_MONTH} variable? Putting a -f /webtrends/SUN/mrw2/access.${CURR_DAY_DAY}${CURR_DAY_MONTH}* won't work, right? I think I need some kind of special character so it knows the wildcard is... (3 Replies)
Discussion started by: LordJezo
3 Replies
Login or Register to Ask a Question