sed search and read the RHS information: Linux 2.6.9-89


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed search and read the RHS information: Linux 2.6.9-89
# 1  
Old 03-09-2010
sed search and read the RHS information: Linux 2.6.9-89

Hi,

I have a config_file.cfg with the content:

Code:
FILE_ID_1=1
FILE_FTP_ID_1=<FTP_SERVER1.COM>
....
 
FILE_ID_2=2
FILE_FTP_ID_2=<FTP_SERVER2.COM>
....

so on for 28 times.

As you might have guessed it; the script I have to write is to read this config file and get the FTP server info based upon the FILE_ID. The user will provide FILE_ID as the parameter to the script (say ftp.ksh).

./ftp.ksh 1

now ftp.ksh script should read the config file and get <FTP_SERVER1.COM> info to connect to ftp server corresponding to FILE_ID_1

if user enters ./ftp.ksh 2

then ftp.ksh script should read the config file and get <FTP_SERVER2.COM> info to connect to ftp server corresponding to FILE_ID_2

can I have a sed command to search for the pattern as:
Code:
REMOTE_IP=`cat config_file.cfg | sed  "s/FILE_FTP_ID_$1/<read the RHS of = in the config file>/"`

In one of the post in this forum https://www.unix.com/shell-programmin...ters-line.html; one of the solution to get a fixed number of chars from a line based on a search pattern was given as
Code:
echo ".R1/new/sv902a.01.per" | sed 's/\(.*\)\(.\{13\}\)$/\2/'

but was not able to use for my purpose Smilie as I am no expert in unix.Also, the number of chars I want to extract is not fixed.
Thanks in advance,

-dips

Last edited by pludi; 03-09-2010 at 03:32 AM.. Reason: removed links, added code tags
# 2  
Old 03-09-2010
The way your config file is structured, just source it:
Code:
$ cat config.cfg
FILE_ID_1=1
FILE_FTP_ID_1=ftp.server1.com
FILE_FTP_USER_1=user1
FILE_FTP_PASS_1=pass1

FILE_ID_2=2
FILE_FTP_ID_2=ftp.server2.com
FILE_FTP_USER_2=user2
FILE_FTP_PASS_2=pass2

FILE_ID_3=3
FILE_FTP_ID_3=ftp.server3.com
FILE_FTP_USER_3=user3
FILE_FTP_PASS_3=pass3

FILE_ID_4=4
FILE_FTP_ID_4=ftp.server4.com
FILE_FTP_USER_4=user4
FILE_FTP_PASS_4=pass4

$ cat ftp.sh
#!/usr/bin/ksh

. ./config.cfg

id=${1:-1}

eval FTP_SERV=\${FILE_FTP_ID_$id}   # MAGIC
eval FTP_USER=\${FILE_FTP_USER_$id} # HAPPENS
eval FTP_PASS=\${FILE_FTP_PASS_$id} # HERE

echo $FTP_SERV
echo $FTP_USER
echo $FTP_PASS
$ ksh ftp.sh 1
ftp.server1.com
user1
pass1
$ ksh ftp.sh 3
ftp.server3.com
user3
pass3

# 3  
Old 03-09-2010
If i understood right you can get ftp server addresses with awk:

Code:
awk -F= '/FTP_ID/ {gsub("\<|\>","",$2);print$2}' infile

# 4  
Old 03-09-2010
Thanks

Thanks Pludi! That's exactly what I was looking for. Sorry to have posted with "sed" keyword.

Thanks Eagle for your time too.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for the information at file

I'm having few question. i'm have a input file. Other information CONNECTIONS "BP-COLLECTOR" J6.4 "BP-TEST".4; +5VS C34.1 U21.1; DEV_I2C_SDA J6.6 R4.1 U18.1; DEVICES "BP-TEST" 1."BP-LED_ANODE" (8 Replies)
Discussion started by: kttan
8 Replies

2. UNIX for Dummies Questions & Answers

Obtaining File information based on String Search

Is there a single Command in Unix to get the following Information when searching for files containing one or more strings in a Unix Directory (including sub directories within it) : 1) Complete filename ( path and filename) 2) Owner of the file 3) Size of the file 4) Last Modified date... (3 Replies)
Discussion started by: pchegoor
3 Replies

3. Shell Programming and Scripting

Read Log Realtime and Parse out Information for a Report

I'm not too fluent at this and having problems comprehending / coming up with a way to do it. Our telephone system is spitting out call information on it's maintenance (serial) port which i have connected to a linux box. I want to be able to monitor the output of this text and when a 911 call is... (1 Reply)
Discussion started by: Pythong
1 Replies

4. UNIX for Dummies Questions & Answers

SED capturing information from a variable

Hi I can't get this line to work. I need to capture what is between Home and plugin_out, where the .* is located. RUN=`echo '${TSP_FILEPATH_PLUGIN_DIR}' | sed -e 's^/results/analysis/output/Home/\(.*\)/plugin_out/g'`; echo ${RUN}; I'm getting the error sed: -e expression #1, char 51:... (1 Reply)
Discussion started by: jdilts
1 Replies

5. AIX

read lv mountpoint information directly from disk

Hello, I need to get the lv mountpoint from the hdisk directly (from vgda i guess) and not from odm or /etc/filesystems I knew the command, but unfortunately I forgot it ;) cheers funksen (5 Replies)
Discussion started by: funksen
5 Replies

6. Shell Programming and Scripting

How to read userid and password information from txt file

Hi Experts, I am writing a shell script (for displaying disk space details) which is logging to 15 different servers using following command. ssh userid@servername It is prompting me for password for all 15 servers when I manually run it. However , soon I would like to schedule this script... (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

7. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

8. Programming

How to read BGP session information with C

Friends, I want to read BGP session information with C ( in FreeBSD ). The program will almost work like a sniffer. My FreeBSD box (which is not a BGP speaker) will look at BGP session information (after catching and parsing it) and take a decision based on the information it sees. :wall: ... (1 Reply)
Discussion started by: asadfx
1 Replies

9. UNIX for Dummies Questions & Answers

Read directory and fill a file with this information

Hello All, Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text. ls /tempdir output is: file1.gfh file2.txt file4.zzz these file names (always with an extention) must be placed in a line and written to... (2 Replies)
Discussion started by: ToXiQ
2 Replies

10. Shell Programming and Scripting

read a part of information from txt and put into the script

Hi, I have a name.txt which is stored: APPLE ORANGE RED BLUE GREEN and my script is: $name=`cat name.txt for file_number in `ls 1 /appl/CH_DATA/archive/CACHE/CDBACKUP$name*.archived however, my script cannot read name.txt and put into my scrip line, I would like the output is to... (18 Replies)
Discussion started by: happyv
18 Replies
Login or Register to Ask a Question