getting data from config file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting data from config file
# 1  
Old 11-18-2005
getting data from config file

pls help..

I need to get the ESSID value for athx

this is the config file..
pls help
Quote:
[ath0]
ESSID=open
MODE=managed
[ath1]
ESSID=wep
MODE=wep
# 2  
Old 11-18-2005
Try this.

Code:
[~/temp]$ cat esham.txt 
[ath0]
ESSID=open
MODE=managed
[ath1]
ESSID=wep
MODE=wep

Code:
[~/temp]$ cat esham.ksh 
#! /bin/ksh

sed -n -e '/\[ath[0-9]\]/{
N
s#ESSID=\(.*\)#\1#p
}' esham.txt

Code:
[~/temp]$ ./esham.ksh
[ath0]
open
[ath1]
wep
[~/temp]$

vino
# 3  
Old 11-18-2005
Better yet...

Code:
[~/temp]$ cat esham.ksh 
#! /bin/ksh

sed -n -e '/\[ath[0-9]\]/{
N
s#.*\(ath[0-9]\).*\nESSID=\(.*\)#\1=\2#p
}' esham.txt

Code:
[~/temp]$ ./esham.ksh 
ath0=open
ath1=wep

# 4  
Old 11-19-2005
can you please explain the usage, how sed is used here.

hope posetive answering
esham
# 5  
Old 11-19-2005
sorry, there is one problem...

the file may have some interfaces like eth0 or ath0..

ie, my file looks like this
Quote:
[ath0]
ESSID=open
MODE=managed
[xyz]
ESSID=shared
MODE=adhoc
[rfg]
ESSID=wepopen
MODE=wep_open
please change the sed arguments according to this..
thanks for ur help
# 6  
Old 11-20-2005
Your sed statement should now be

Code:
sed -n -e '/^\[.*]/{
N
s#^\[\(.*\)\]\nESSID=\(.*\)#\1=\2#p
}' esham.txt

Read it as:

- for any line starting with [ followed by some combination of characters and then a closing ]
- append the next line into the pattern space
- For the two lines that are present in the pattern space, collect the interfaces and its value and print it.
- Read the entries from esham.txt
# 7  
Old 11-20-2005
Hi,

Thanks for the reply..it worked great..
but one more question....

Y iam not able to make it one line... like

Quote:
sed -n -e '/^\[.*]/{ N s#^\[\(.*\)\]\nESSID=\(.*\)#\1=\2#p }' esham.txt
Iam getting the following error:
Quote:
sed: -e expression #1, char 13: Extra characters after command
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Apache virtual host config vs global config problem

Hi folks, I am trying to configure Apache webserver and also a virtual host inside this webserver. For Global server config: /var/www/html/index.html For virtual host config: /var/www/virtual/index.html Both client10 & www10 are pointing to 192.168.122.10 IP address. BUT, MY... (1 Reply)
Discussion started by: freebird8z
1 Replies

2. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

3. Shell Programming and Scripting

Read Data from Config file using Perl

Hi All, Can anyone please explain me how to read data from config file in Perl. Suppose i have a config file named cfile. The data in config file is name=parth lname=mittal user=2007 hostname=fluoride username=parthmittal password=XXXXXX account=unix url=www.unix.com ... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

4. Shell Programming and Scripting

how to send config file

hi all please give me some idea about how to send xml file from one c++ pgm to other pgm. (1 Reply)
Discussion started by: shubhig15
1 Replies

5. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

6. Shell Programming and Scripting

Parse config file data to script variable

I have a script with few pre defined variables. Also have a config file. Something like this. # config file # Define Oracle User MOD1_TAG=abcde MOD2_TAG=xyzabc MOD3_TAG=def I need to parse the config file and have each of the value copied to different variables. Please suggest what... (1 Reply)
Discussion started by: souryadipta
1 Replies

7. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

8. Shell Programming and Scripting

Copy data and send it to other file, with diff config

I need a new script to 'grep' data from files in var and send it to another file in var folder with diff output, but like you now my Now How is very, very small then to have a idea is something like this: in file text1.txt have a few lines like this one: Y: { XXX1 { XXX2 YYYY { IIIIIIII... (0 Replies)
Discussion started by: single
0 Replies

9. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

10. Shell Programming and Scripting

using config file

Hello I got script where is defined path name, connect string to database and name of the log file. I would like to create a new config file which will be consists of these path name, connect string and name of the log file. But I don't know how to use this config file into the main... (1 Reply)
Discussion started by: mape
1 Replies
Login or Register to Ask a Question