Complete Newbie requiring help

Greetings

Just joined this forum and a complete newbie. So please be gentle :slight_smile:

I've never really scripted before nor had a project where I required to write some code. However I have a large project which I am currently doing by manually. I was wondering if someone could help me determine what scripting language to use and possibly help with assisting me with what needs to be done.

I have a file with entries in the following format

[some text.......RedHat]
rubbish text
more text

more text

[some text.......SUSE]
rubbish text
more text

more text

[some text.......Solaris]

What I would like to create is a script that takes arguments (in this case RedHat,SUSE and Solaris] and then searches a file. When it reaches the first argument it copies the entire section starting from [ and ending when it gets to the next [.

With each section, it replaces 'rubbish' with 'good' and it saves it to a file in the format <argument>.txt

Thank you for any help offered or advice offered.

Snoops

If each section ended with something predictable (e.g. the Solaris section ends with EndSolaris) then you could use:

awk '/Solaris/,/EndSolaris/' inputfile > solarisoutputfile1

To extract the Solaris section.

Once the Solaris section is in its own file you could then use:

sed 's/rubbish/good/' solarisoutputfile1 > solarisoutputfile2

To replace "rubbish" with "good".

If the "rubbish" you want to replace is always at the beginning of the line and there are mentions of "rubbish" that are not at the beginning of the line you do not want to replace you could use:

sed 's/^rubbish/good/' solarisoutputfile1 > solarisoutputfile2

Where the "^" (caret) denotes start of line.

If on the other hand you do want to replace absolutely all mentions of "rubbish" with "good" then you would use:

sed 's/rubbish/good/g' solarisoutputfile1 > solarisoutputfile2

Where the g denotes global replace, without the g only the first mention of "rubbish" in each line would get replaced.

Thank you so much for your help. Really appreciate it.

Also have made a note of the command you have given for future reference. :b:

Unfortunately the sections do not have a unique entry. However each section begins with a [

In Pseudo code what I want to do is:

For argument1 to argumentn do
read argument
Search file for argument
go back to the first [ on the line
extract everything until you reach the next [
save to file argument1.txt

I think once I have this then everything else I need to do I will be able to add to the script.

Thanks again

Your data sample is not clear, post a new sample data and don't forget the [code] tags.

Here is the Text file

[HKEY_LOCAL_MACHINE\SOFTWARE\STP\Configuration\Request Systems\FIXEngineCIT]
"Machine"="LDN-PRD-FIX7"
"Port"="14822"
"Enabled"="1"
"ProcessingOptions"="1049502"
"Partitions"="FCFG"
"DefaultPartition"="FCFG"
"RemoteConfiguration"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\STP\Configuration\Request Systems\FIXEngineCQS]
"Machine"="LDN-PRD-FIXV12"
"Port"="11062"
"Enabled"="1"
"ProcessingOptions"="1049246"
"Partitions"="FEFG1"
"DefaultPartition"="FEFG1"
"RemoteConfiguration"="0"
"WaitForAllPartitions"="0"
"EventSink"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\STP\Configuration\Request Systems\FIXEngineCQSEQ]
"Machine"="LDN-PRD-FIXV11"
"Port"="14182"
"Enabled"="1"
"ProcessingOptions"="1049246"
"Partitions"="FEFG2"
"DefaultPartition"="FEFG2"
"RemoteConfiguration"="0"
"WaitForAllPartitions"="0"
"EventSink"="0"

For example I want to run a script and give it 2 arguments, FixEngineCQSEQ & FEFG4

The script should look at the file, extract the entry for FixengineCQSEQ, Change the defaultpartition and partions to FEFG4 (only for this entry) and then save the current file and the section to file LDN-PRD-FIXV11.txt (as specified in machine field)

Is this clearer?

thank you