Read a file and replace values in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a file and replace values in a script
# 8  
Old 05-06-2016
Quote:
Originally Posted by samrat dutta
I made a comman seperated file as below .
Property file :
Code:
PSIHUBV1,PSIHUB04

Below is my script but when i execute it i find the actual command "cfsend" is not getting executed and the output(given below) is only giving me same command as a result.

Script:
Code:
 #! /bin/bash
file=/usr/opt/temp/aorc.prop
tr ',' '\n' < $file | while read node; do 
echo cfsend n:"${node}" port:46464 uid:PSMFT pwd:Tib3 pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" >> out.txt
done

Output :
Code:
cfsend n:PSIHUBV1 port:46464 uid:PSMFT pwd:Tib3 pn:CHCKDIR ud:5563 trtype:c rcmd:pwd
cfsend n:PSIHUB04 port:46464 uid:PSMFT pwd:Tib3 pn:CHCKDIR ud:5563 trtype:c rcmd:pwd

Any help with more input Smilie
Please, remove the echo. I presume that it was there for testing purposes.
This User Gave Thanks to Aia For This Post:
# 9  
Old 05-15-2016
Hi I removed the echo but i am not able to pass the ${node} value from the input file to the current script. Basically my requirement again is to read a input file which has comma seperated values . Now in the script i need to replace those values where i have put ${node}. Below is the input file and the script. i presume a error in my while statement !!

Input File :--
Code:
PSIHUBV1,PSIHUB04

Script :--
Code:
 #! /bin/bash
file=/usr/opt/temp/aorc.prop
tr ',' '\n' < $file | while read node; do 
cfsend n:"${node}" port:46464 uid:PSMFT pwd:Tib3 pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" >> out.txt
done

# 10  
Old 05-16-2016
With the output from the echo commands you showed us in post #7 in this thread, it appears that the tr and while read loop are behaving as expected. What makes you believe that it is not working correctly?

Note that the script should now work with an input file that contains a list of comma- and/or newline-separated list of hosts. It will not, however, make any attempt to grab only a hostname from an input line like:
Code:
variable=hostname

Are you saying that your script doesn't work if you feed it data from a file in this alternative format?

Note also that if a first line in a shell script starts with a space character followed by #!, that line is NOTHING but a comment; it does not affect what interpreter is used to process that script. #! in a script has absolutely no effect on the running of that script unless those are the 1st two characters in the file. (And, there shouldn't be a space following the #! either.)
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 05-18-2016
Thanks All. It worked. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to replace a string with pattern read from a file

I have two files blocks.txt and rules.txt. In blocks.txt i have the following entries Linux1 Linux2 Linux3 ..... Linux10 In rules.txt i have the lines where a filename pattern starts like 'blk-name.*' I want to replace 'blk-name' with the names read from blocks.txt file I tried... (2 Replies)
Discussion started by: Jag02
2 Replies

2. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

3. Shell Programming and Scripting

Shell script to read little complex values

Dear All, I have attached a file. In that I want to read some of the values like 1. ExecutionTime 2. ClockTime etc. I want to read at a specified time. How can I do that? Thanks & Regards, linuxUser_ (9 Replies)
Discussion started by: linuxUser_
9 Replies

4. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

5. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

6. Shell Programming and Scripting

Read values from file.

I have a config file of this format: Company= Alpha Tech From Email = AlphaTech@Alphatech.com Pass = Passowrd To Email = abc@hotmail.com Smtp=smtp.live.com:587 I want to read these values from this file and use in a command to send email. I am trying grep but it gives full line. I just... (8 Replies)
Discussion started by: kashif.live
8 Replies

7. Shell Programming and Scripting

Read record from the text file & assign those values to variables in the script

For eg: I have sample.txt file with 4 rows of record like: user1|password1 user2|password2 user3|password3 user4|password4 The username and password is sepsrated by '|' I want to get the 1st row value from the file and assign it to two different variables(username and password) in my... (1 Reply)
Discussion started by: priya001
1 Replies

8. Shell Programming and Scripting

Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log. An example of the log file content: ... (2 Replies)
Discussion started by: gman2010
2 Replies

9. Shell Programming and Scripting

Read values from a file

Hi , I have a file with the following content I need the read the year and reporting from this file and store them in variables. I understand that we can read the file delimited by'=' but not sure how to extract the values correctly. Thanks in advance Regards (3 Replies)
Discussion started by: w020637
3 Replies

10. Shell Programming and Scripting

Korn Shell Script - Read File & Search On Values

I am attempting to itterate through a file that has multiple lines and for each one read the entire line and use the value then to search in other files. The problem is that instead of an entire line I am getting each word in the file set as the value I am searching for. For example in File 1... (2 Replies)
Discussion started by: run_unx_novice
2 Replies
Login or Register to Ask a Question