Just joined this forum and a complete newbie. So please be gentle
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
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.
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.
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)