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 :

_TOOLS/_CONFIG

The Directory were are stored the OLD configuration files is :

_TOOLS/_CONFIG/_HISTO_FIC_CFG

Here is the contain of one configuration file

#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 :

/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 :

#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

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.

sed 's/#/:/g' _TOOLS/_CONFIG/config.cfg > _TOOLS/_CONFIG/newconfig.cfg
nawk '/tronc/{p=$2}/branche# /{x=p"/"$2}/Spec/{x=p"/"$NF}x{print x;x=n}' config.cfg
# 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
# 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
#

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.

Ok, no pb. FYI i updated my previous post

1 Like

Thanks ctsgnb,

That's make you now my new best friend :wink:

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.