Help with dynamic configure cfg files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with dynamic configure cfg files
# 8  
Old 05-21-2010
thanks for your codesnap,but it is not working,it's never enter case.

---------- Post updated at 06:20 AM ---------- Previous update was at 04:11 AM ----------

Quote:
Originally Posted by frans
Maybe, this should do the job (take care : it modifies the config files (make a backup))
Code:
#!/bin/bash
while read A S B
do
    case $A in
        filename)    # process new file
            FILE=bin/$B
            unset SECT
            [ -f $FILE ] || { echo "$FILE not found"; unset FILE; }
        ;;
        sectionname) # new section
            [ -z "$FILE" ] && continue
            SECT="$B"
            # return the line number of section in $FILE
            N=$(grep -Fwn "$SECT" $FILE | cut -d':' -f1) || { echo "$SECT not found in $FILE "; unset SECT; }
        ;;
        *)    # process parameter
            if [ -n "$FILE" ] && [ -n "$SECT" ]
            then
                ((N++))
                sed -i "${N}i\n$A $S $B" $FILE
            fi
        ;;
    esac
done < configuration.cfg

Hi frans;
Really nice code,now it's working fine after little modification,but it's writting in destnation file with leading with a space how i remove it.for example...
spaceparameter1
spaceparameter2
like this,it's mismatch the existing parameter.

---------- Post updated at 06:26 AM ---------- Previous update was at 06:20 AM ----------

Quote:
Originally Posted by frans
Maybe, this should do the job (take care : it modifies the config files (make a backup))
Code:
#!/bin/bash
while read A S B
do
    case $A in
        filename)    # process new file
            FILE=bin/$B
            unset SECT
            [ -f $FILE ] || { echo "$FILE not found"; unset FILE; }
        ;;
        sectionname) # new section
            [ -z "$FILE" ] && continue
            SECT="$B"
            # return the line number of section in $FILE
            N=$(grep -Fwn "$SECT" $FILE | cut -d':' -f1) || { echo "$SECT not found in $FILE "; unset SECT; }
        ;;
        *)    # process parameter
            if [ -n "$FILE" ] && [ -n "$SECT" ]
            then
                ((N++))
                sed -i "${N}i\n$A $S $B" $FILE
            fi
        ;;
    esac
done < configuration.cfg

Hi frans;
Really nice code,now it's working fine after little modification,but it's writting in destnation file with leading with a space how i remove it.for example...
spaceparameter1
spaceparameter2
like this,

---------- Post updated at 08:52 AM ---------- Previous update was at 06:26 AM ----------

Quote:
Originally Posted by frans
Maybe, this should do the job (take care : it modifies the config files (make a backup))
Code:
#!/bin/bash
while read A S B
do
    case $A in
        filename)    # process new file
            FILE=bin/$B
            unset SECT
            [ -f $FILE ] || { echo "$FILE not found"; unset FILE; }
        ;;
        sectionname) # new section
            [ -z "$FILE" ] && continue
            SECT="$B"
            # return the line number of section in $FILE
            N=$(grep -Fwn "$SECT" $FILE | cut -d':' -f1) || { echo "$SECT not found in $FILE "; unset SECT; }
        ;;
        *)    # process parameter
            if [ -n "$FILE" ] && [ -n "$SECT" ]
            then
                ((N++))
                sed -i "${N}i\n$A $S $B" $FILE
            fi
        ;;
    esac
done < configuration.cfg

Hi frans;
your code is nice working after little bit changes,but when inserting parametres in destination files,start with space...like
spaceParameter1
spaceParameter2
..................
how i remove this leading space?
Now this issue is resolved.
Thanks

Last edited by suryanarayan; 05-24-2010 at 01:06 AM.. Reason: give some example for clarity purpose
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Kickstart using anaconda-ks.cfg

Heyas I'm trying to build a live image using livecd-tools (livecd-creator), but this time i'd like to reuse the /root/anaconda-ks.cfg. System: Fedora 3.16.7-200.fc20.x86_64 The building starts, the download begins, but it fails with networking. MAIN.ks # Based on: fedora-live-base.ks... (0 Replies)
Discussion started by: sea
0 Replies

2. Shell Programming and Scripting

Help Dynamic looping based on files

Hi I have to run the script (a part of the code) in a loop for the no of times the files present in the directory, by taking one file and process and next another file. For example, if we do ls and the result have: $ls abc.dat def.dat ghi.dat The script code should loop for 3... (4 Replies)
Discussion started by: karumudi7
4 Replies

3. Solaris

Configure network in unix with dynamic ip on my DHCP server?

can anyone tell me how can i configure network in unix with dynamic ip on my DHCP server?? (7 Replies)
Discussion started by: Reham.Donia
7 Replies

4. Red Hat

Help in ANACONDA-ks.cfg

i have automated installation of my proprietory linux.. using PXE. it all goes well. but after complete installation, while using the admin interface.. i am facing display problems. is it due to package dependencies.? or i have to write post script in anaconda-ks.cfg file??? can some one tell... (10 Replies)
Discussion started by: jayesh_j
10 Replies

5. Shell Programming and Scripting

Help - Using Find command on dynamic files on KSH

Hi Forum. When I run the following find command, I get the desired results: find . \( -name a.out -o -name '*.o' -o -name 'core' \) -type f -ls I want for my script to dynamically calculate and assign a variable var1 to contain all the files that I want to search instead of hard-coding. ... (2 Replies)
Discussion started by: pchang
2 Replies

6. BSD

configure /usr/local/etc/be-agent.cfg

hi Howto configure Ralus at /usr/local/etc/be-agent.cfg on freeBSD 7.0 for Backup Exec 9.1? I've tried the following: # cat /usr/local/etc/be-agent.cfg name bsd.domain export / as root export /usr as usr export /var as var export /tmp as tmp force_address 10.10.1.50 tell... (0 Replies)
Discussion started by: ccc
0 Replies

7. UNIX for Advanced & Expert Users

Dynamic Downloading and executing of ELF files

Dear Group, I want to prepare an ELF file which can be downloaded dynamically to any address in the moemory and executes as a new task/thread/process. 1) for this what are all the compileation, linker options while building the ELF file? 2) which parts of ELF file has to modified while... (1 Reply)
Discussion started by: ravinder.are
1 Replies

8. UNIX for Dummies Questions & Answers

Problem with shared dynamic library files

I am having a major problem. Most of the commands that i am running on my centos 5 system is giving the error of type: <dynamic shared library file>:open failed: No such file or directory For example: libgcc_s.so.1: open failed: No such file or directory How can i solve this? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

9. HP-UX

dynamic names for .tar.gz files?

Hi All, I have a requirement to zip and compress files with dynamic names (which includes date and time component in their names) needs to be compressed with same name. for example I have a file T.30.SLS_ORD.SO.27.2_2_2.20080623.041415.dat which needs to archived as... (1 Reply)
Discussion started by: srinivas_paluku
1 Replies

10. UNIX for Advanced & Expert Users

How to Read config (.cfg) files using shell scripting

Hello Friends I am new to this forum and this is my first post. I have to write a script in which i have to read data from a configuration ( .cfg) file. And also i have to execute/call some already written scripts from this script. Can you people plpease help me on this regards. Thanks... (5 Replies)
Discussion started by: smallwonder
5 Replies
Login or Register to Ask a Question