Function and LOOP

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Function and LOOP
# 1  
Old 02-23-2011
Function and LOOP

Hello,

I need help :

I've got configurations files in two differents directory. Each configuration files contains some information that I must have in order to send specific command.

I do not know how to do it. I belive I need a loop in function but I can't make it work.

Extension of configuration files are .cfg

The current directory is :

Code:
_TOOLS/_CONFIG

The Directory were are stored the OLD configuration files is :

Code:
_TOOLS/_CONFIG/_HISTO_FIC_CFG

Here is the contain of one configuration file

Code:
#tronc_staf# /OPERATIONNEL/PSY2V4R1

#branche# ALLEGES_BEST
#branche# TRACES
#nbr_feuille_par_#branche# PHYSICAL_MODEL/FORECAST 98

#branche#supprime# RESTART_SAT
#brancheSpecifique# RESTART_SAT RESTARTICE RESTARTICE
#brancheSpecifique# RESTART_SAT RESTART RESTART

Info :

I must have, for each configuration file a resulat that will looks like this :

Code:
/OPERATIONNEL/PSY2V4R1/ALLEGES_BEST
/OPERATIONNEL/PSY2V4R1/TRACES
/OPERATIONNEL/PSY2V4R1/PHYSICAL_MODEL/FORECAST
/OPERATIONNEL/PSY2V4R1/RESTARTICE
/OPERATIONNEL/PSY2V4R1/RESTART

NOTE : for #brancheSpecifique# I need the last part of the line

ex : #brancheSpecifique# RESTART_SAT RESTART RESTART : I am keeping the last RESTART

I do not need to keep :
Code:
#branche#supprime# RESTART_SAT

I hope you will be able to help me. I can't do it on my own. The LOOP will get all informations in ALL configuration files (current and OLD)

Thanks
# 2  
Old 02-23-2011
Using the hash # as a field separator in config file is a bad choice and may lead to confusion.
By convention, the # is used for commenting lines, so i suggest you to choose another delimiter (:;, colon in the example below) so you will stay compliant with the standard.

Code:
sed 's/#/:/g' _TOOLS/_CONFIG/config.cfg > _TOOLS/_CONFIG/newconfig.cfg

Code:
nawk '/tronc/{p=$2}/branche# /{x=p"/"$2}/Spec/{x=p"/"$NF}x{print x;x=n}' config.cfg

Code:
# cat tst
#tronc_staf# /OPERATIONNEL/PSY2V4R1

#branche# ALLEGES_BEST
#branche# TRACES
#nbr_feuille_par_#branche# PHYSICAL_MODEL/FORECAST 98

#branche#supprime# RESTART_SAT
#brancheSpecifique# RESTART_SAT RESTARTICE RESTARTICE
#brancheSpecifique# RESTART_SAT RESTART RESTART

Code:
# nawk '/tronc/{p=$2}/branche# /{x=p"/"$2}/Spec/{x=p"/"$NF}x{print x;x=n}' tst
/OPERATIONNEL/PSY2V4R1/ALLEGES_BEST
/OPERATIONNEL/PSY2V4R1/TRACES
/OPERATIONNEL/PSY2V4R1/PHYSICAL_MODEL/FORECAST
/OPERATIONNEL/PSY2V4R1/RESTARTICE
/OPERATIONNEL/PSY2V4R1/RESTART
#


Last edited by ctsgnb; 02-23-2011 at 06:12 AM..
# 3  
Old 02-23-2011
Hi ctsgnb,

Thanks for the info but I can't change this. Is the way all configurations files are made. I am not the owner of the configuration files so I can't change them.

Thanks.
# 4  
Old 02-23-2011
Ok, no pb. FYI i updated my previous post
This User Gave Thanks to ctsgnb For This Post:
# 5  
Old 02-23-2011
Thanks ctsgnb,

That's make you now my new best friend Smilie

I will try this. I believe I will have to send this command line on both of directories to create a temporary file and then use a loop to read it line by line to send my specific command.

Thanks again for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read function is going in infinite in another script having while loop

Hello Experts, I have created one user confirmation process that will ask for user input. I have created one func for it. The issue is if i call it as normal then it works fine but if i am calling it in another script(in while loop) . It is going in infinite loop and not asking for user input. ... (8 Replies)
Discussion started by: looney
8 Replies

2. Shell Programming and Scripting

How to pass function parameter to do loop?

Hi All, I have created one function for KSH and was running well with one parameter input since I just had to use $1 to get the parameter. Now I want to do loop for each parameter(actually filenames) . I have try to use do loop, but $i does not resolve to parameter instead it resolves to 1,... (5 Replies)
Discussion started by: mysocks
5 Replies

3. UNIX for Advanced & Expert Users

Help - Infinite Loop: Error in trap function

Hi, I was working on implementing error handling in my bash scripts, and decided to use trap to send myself an email incase of any errors. But it seems that somethings has gone wrong, and I am continuously getting same emails for an old error repeatedly (even though I have stopped/killed all... (1 Reply)
Discussion started by: cool.aquarian
1 Replies

4. Shell Programming and Scripting

Using multiple gsub() function under a loop in awk

Hi ALL, I want to replace string occurrence in my file "Config" using a external file named "Mapping" using awk. $cat Config ! Configuration file for RAVI ! Configuration file for RACHANA ! Configuration file for BALLU $cat Mapping ravi:ram rachana:shyam ballu:hameed The... (5 Replies)
Discussion started by: useless79
5 Replies

5. Shell Programming and Scripting

If loop inside function not working.

check_deplver () { dir=/abc/def/ghi if ssh -o StrictHostKeychecking=no $1 "" 2> /dev/null then echo " output is " ssh -o StrictHostKeychecking=no $1 "ls -lrt $dir | grep -i abc" 2> /dev/null else echo " directory not presnt" fi } This is not working. But... (7 Replies)
Discussion started by: NarayanaPrakash
7 Replies

6. UNIX for Dummies Questions & Answers

while loop stops after a function...

my ksh script is not working... i wanna remove lines in file2.txt from file1.txt # cat file1.txt this is line one this is line two this is line three this is line four this is line five # cat file2.txt this is line two this is line three # cat my_script.ksh #!/bin/ksh i=1 y=1... (8 Replies)
Discussion started by: curtis911
8 Replies

7. Shell Programming and Scripting

call a function in for loop

Hi all, I am trying to call a function in for loop in the below format #!/bin/bash abc() { commands } for (( i=0; i<=10; i++ )) do abc done The error i am getting when trying to execute: syntax error: unexpected end of file canany one help me where i am going wrong?? (5 Replies)
Discussion started by: gsr_kashyap
5 Replies

8. Programming

__read_nocancel Function Causes Infinite Loop

Does anyone know what __read_nocancel does and why it would go into an infinite loop? What I have gathered in my searches is that it pertains to server code. Yet, I'm not running this application in server mode. NOTE: There are server functions in the shared object, but the specific code... (3 Replies)
Discussion started by: marcus121
3 Replies

9. Shell Programming and Scripting

how to get the similar function in while loop or for loop

Dear all How to write the shell script for the following statement: (C programming) for (i=0;i<30;i++) { if i=1 continue *skip this number (To do function here....) ... } similar statement in while loop.... I wrote the script in sh... (3 Replies)
Discussion started by: trynew
3 Replies

10. UNIX for Dummies Questions & Answers

Menu function stuck in a loop?

I having problem when I call this cleanupmenu function within a script. It continuously loops and goes to selection * That wasn't a valid selection. I have to kill it everytime to stop it. What am I doing wrong. I use this function menu in several other scripts and I don't have this problem at... (2 Replies)
Discussion started by: darthur
2 Replies
Login or Register to Ask a Question