Variable from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable from a text file
# 1  
Old 05-19-2010
Variable from a text file

I have a variable from a txt file, can i create more variables from the same txt file?
Code:
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 is 1st variable
Code:
printer_list="$(awk -F: '{print $1 }' diffs.txt | cut -c11-18)"

i want to create three others from the same text file, with
LPD,
IP Address and
PORT

Can it be done?
I tried this , but to no avail
Code:
#port="$(awk -F: '{print $4}' diffs.txt )"

#drv="$(awk -F: '{print $2}' diffs.txt )"

#IP="$(awk -F: '{print $3}' diffs.txt )"

# 2  
Old 05-19-2010
Code:
> printer_list=`awk -F"[ :]" '{print $3}' diffs.txt`
$> echo $printer_list
0117bd1 2001bl7 2201bl7 5001bl1

Code:
drv=`awk -F"[ :]|//" '{print $5}' infile`
IP=`awk -F"[ :]|//" '{print $7}' infile`
port=`awk -F"[ :]|//" '{print $8}' infile`
$> echo $drv
lpd socket socket lpd
$> echo $IP
172.25.29.60 172.25.44.188 172.25.11.170 172.25.11.203
$> echo $port
515 9100 9100 515

# 3  
Old 05-19-2010
Ok thanks, that works BUT
BUT its not adding the printer with other three variables as specified in the lpadmin statement
Code:
$BIN/lpadmin -p "$P" -E -D "$drv"://"$IP":"$port"

here is the script being run
Code:
+ echo \n\t Adding printers 5001x02 !!!!
         Adding printers 5001x02 !!!!
+ /usr/lbin/lpadmin -p 5001x02 -E -D lpd
socket
socket
lpd
lpd
lpd://172.25.29.60
172.25.44.188
172.25.11.170
172.25.11.203
172.25.12.160
172.25.12.160:515
9100
9100
515
515
515
+ echo \n\t Printer  created


If i do a lpstat -v (which displays printer)
it does not give me the required details
Code:
lpstat -v 5001x02
device for 5001x02: ///dev/null

WHERE IS THE $drv,$IP and the $PORT
Is there something amiss
# 4  
Old 05-19-2010
I think we had that already in your 2 other threads, building your commands together by those printer informations etc.. At the end I think I am not able to help you, sorry. Hopefully another user here can.
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

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

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

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

10. UNIX for Dummies Questions & Answers

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 then cat /export/home/bdodym/callout6.msg |... (6 Replies)
Discussion started by: tjhorwood
6 Replies
Login or Register to Ask a Question