Text file to a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Text file to a variable
# 1  
Old 07-24-2008
Text file to a variable


I have a variable which is not being populated with the contents of a text file, and I'm wondering if anyone happens to know how to do this for a sh type script?

#!/bin/sh
set alertperson = cat /export/home/bdodym/alert.person
if [ -f /export/home/bdodym/critabend.tag ]
then
cat /export/home/bdodym/callout6.msg | rmail $alertperson
rm /export/home/bdodym/critabend.tag
fi

Basically, the alertperson variable is not reading the contents of /alert.person (which is a text file simply containing 1 email address).

I appreciate any assistance....

Tim
# 2  
Old 07-24-2008
Code:
alertperson=`cat /export/home/bdodym/alert.person`

# 3  
Old 07-24-2008
I wish it were that easy Ikon!

Amended script:
#!/bin/sh

alertperson = cat /export/home/bdodym/alert.person
echo $alertperson
if [ -f /export/home/bdodym/critabend.tag ]
then
cat /export/home/bdodym/callout6.msg | rmail $alertperson
rm /export/home/bdodym/critabend.tag
fi

Response:
6check2.sh: alertperson: not found

Recipient names must be specified
# 4  
Old 07-24-2008
Hammer & Screwdriver

Beware of character spacing - very important in the world of unix.

Code:
alertperson=$(cat /export/home/bdodym/alert.person)
echo $alertperson

# 5  
Old 07-24-2008
...thankyou, but still its proving tricky this!!

Amended script:
#!/bin/sh

alertperson=$(cat /export/home/bdodym/alert.person)
echo $alertperson
if [ -f /export/home/bdodym/critabend.tag ]
then
cat /export/home/bdodym/callout6.msg | rmail $alertperson
rm /export/home/bdodym/critabend.tag
fi

Response:
6check2.sh: syntax error at line 3: `alertperson=$' unexpected
# 6  
Old 07-24-2008
Question

What is in your file alert.person?

Code:
> cat ~/tmp/alert/alert.person
Mickey Mouse
> alertperson=$(cat ~/tmp/alert/alert.person)
> echo $alertperson
Mickey Mouse
> echo "$alertperson"
Mickey Mouse

# 7  
Old 07-24-2008
worked for me... It put the contents of alert.person in the variable $alertperson.

Code:
# echo "Jim Smith" > alert.person
# alertperson=`cat alert.person`; echo $alertperson
Jim Smith
#

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract text from file then write variable

I have a text file that has many lines, and for each line I need to extract different sections of text, then write several variables from the data. I can split out the various sections by selecting their position on each line as the column sizes will never vary. A sample of my text file is below... (2 Replies)
Discussion started by: kcpoole
2 Replies

2. UNIX for Dummies Questions & Answers

[Help] Adding text to a variable line in a file

Hey guys, I need to write a script that will add a specific text at the end of a specific line (of a text file). but the line is a variable this is my text file : device_2 ansible_ssh_host=127.0.0.1 ansible_ssh_port=30000 ansible_ssh_user='root' device_2 ansible_ssh_host=127.0.0.1... (1 Reply)
Discussion started by: OdedOvdat
1 Replies

3. Shell Programming and Scripting

Read a file name from a text file and save it in a variable

i have a text file consists of different file names like: line 1: lib/libIMb.so message broker file line 2: lil/imbdfg.lil message broker file i need to extract libIMb.so and imbdfg.lil files from those lines and save them in a variable. so that i can search for... (9 Replies)
Discussion started by: santosh2626
9 Replies

4. Shell Programming and Scripting

Defined Variable from text file

Hi Guys, I have one text file ABC.txt...It have 3 lines List=/home/klk/dir/ABC.txt Leajnk123 KJUHIO1234 IJOKIJ7676 I want use as different variable of each line.Just like X=firstline Y=Secound Line Z=Third Line (4 Replies)
Discussion started by: asavaliya
4 Replies

5. Shell Programming and Scripting

replace text in file using variable

Hi, I'm making a script that automaticaly set file size and path in xml file. I tried with : sed -i 's/BOOTPATH/TEST/g' file.xml it works fine but if I use a viriable : sed -i 's/BOOTPATH/$bootpathf/g' file.xml with this one, no change are made. I don't understand why. If a make a ... (13 Replies)
Discussion started by: Toug
13 Replies

6. Shell Programming and Scripting

Assigning a value as a variable from a text file

I have a txt file output.txt Freq = 1900 L = 159I want to assign the values to a variable so that i can further use it in some other script. like F=1900 Len=159 etc i tried doing something with awk but dosent work F=$(awk 'BEGIN {}/Freq/ {split ($2,a);depth=a};printf "%d\t,... (2 Replies)
Discussion started by: shashi792
2 Replies

7. Shell Programming and Scripting

Variable from a text file

I have a variable from a txt file, can i create more variables from the same txt file? diffs.txt device for 0117bd1: lpd://172.25.29.60:515 device for 2001bl7: socket://172.25.44.188:9100 device for 2201bl7: socket://172.25.11.170:9100 device for 5001bl1: lpd://172.25.11.203:515 here... (3 Replies)
Discussion started by: ggoliath
3 Replies

8. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

9. UNIX for Dummies Questions & Answers

Searching a text file and assigning it to a variable

Hi Gurus, I am new to unix.I have a requirement as below I have text file like a.txt which contains a.txt hi hello process update status Ok to Proceed no issues good data arrangement My requirement here is i need to read the file and check for the words "OK to Proceed" and if... (2 Replies)
Discussion started by: pssandeep
2 Replies

10. UNIX for Dummies Questions & Answers

Assigning value in a text file to a variable

Hi, I need to place a number located in a text file in a variable so I can perform if/then comparison. How would I go about doing this? Using A=awk '{print $2}' maintenance_date.tmp does not seem to work. Thanks (1 Reply)
Discussion started by: mojoman
1 Replies
Login or Register to Ask a Question