Complete Newbie requiring help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complete Newbie requiring help
# 1  
Old 09-25-2009
Complete Newbie requiring help

Greetings

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

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
# 2  
Old 09-26-2009
If each section ended with something predictable (e.g. the Solaris section ends with EndSolaris) then you could use:
Code:
awk '/Solaris/,/EndSolaris/' inputfile > solarisoutputfile1

To extract the Solaris section.

Once the Solaris section is in its own file you could then use:
Code:
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:
Code:
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:
Code:
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.
# 3  
Old 09-26-2009
Thank you so much for your help. Really appreciate it.

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

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
# 4  
Old 09-26-2009
Quote:
Originally Posted by snoops
[some text.......RedHat]
rubbish text
more text

more text
Your data sample is not clear, post a new sample data and don't forget the [code] tags.
# 5  
Old 09-28-2009
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

Last edited by snoops; 09-28-2009 at 03:28 PM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a script requiring a pause for user input

Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output. I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem... (9 Replies)
Discussion started by: Buddyluv
9 Replies

2. Programming

Unable to use libcurl to access a site requiring client authentication

I’m using the below snipped for setting the certificate and key for client authentication. curl_easy_setopt(curl,CURLOPT_SSLCERT,"clientCert.pem"); curl_easy_setopt(curl,CURLOPT_SSLCERTPASSWD,"changeit"); curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM"); ... (2 Replies)
Discussion started by: old_as_a_fossil
2 Replies

3. UNIX for Dummies Questions & Answers

Complete Newbie looking for advice

Hi everyone! I've been browsing the forum for a couple of days, and thought it was about time to chime in. I'm having a pre-mid-life mid-life crisis (I think), and am seriously debating a career shift. I currently use a bash shell in my day to day work (very basic file management, FTP, backups,... (8 Replies)
Discussion started by: Bravestarr
8 Replies

4. Hardware

Wireless works, then dies requiring a reboot

Hello, I am having a problem with my wireless. Seems to be a relatively new problem over the past few weeks. I have an intel wireless. It seems like it can be fine for days, then in will quite working to the point a reboot is necessary. It may happen once and be fine, or may happen several times... (0 Replies)
Discussion started by: Narnie
0 Replies

5. Shell Programming and Scripting

BASH: Any Way to Get User Input Without Requiring Them to Hit the Enter Key?

I'm working on making a menu system on an HP-UX box with Bash on it. The old menu system presents the users with a standard text menu with numbers to make selections. I'm re-working the system and I would like to provide something more akin to iterative search in Emacs. I have a list of 28... (2 Replies)
Discussion started by: deckard
2 Replies

6. UNIX for Dummies Questions & Answers

BASH complete-filename & menu-complete together

Hi, Does anyone know how to make BASH provide a list of possible completions on the first tab, and then start cycling through the possibilites on the next tab? Right now this is what I have in my .bashrc: bind "set show-all-if-ambiguous on" bind \\C-o:menu-complete This allows... (0 Replies)
Discussion started by: Mithu
0 Replies

7. UNIX for Dummies Questions & Answers

Qmail requiring SMTP auth

Has anyone gotten netqmail patched with qmail-smtp-auth to not just allow, but require ESMTP authentication? I'm in the processes of setting up a port 587 (submission) server for my remote users to be able to send mail through while they're on the road, but I don't want it to usable without... (0 Replies)
Discussion started by: vertigo23
0 Replies

8. UNIX for Dummies Questions & Answers

A complete Unix Newbie

I would like to know if I should install unix over a windows 98. I want to use a home computer to host websites right now, but I know how much Windows likes resources ;) So, my question is... Should I get a Unix OS? If no, then do not read more and just reply :) If yes, then, which one? How... (2 Replies)
Discussion started by: Afinita
2 Replies

9. UNIX for Dummies Questions & Answers

complete newbie

ok so i am trying redhat linux and i create a partiton and install it no worries then i start and i cant access any of my other drives i can mount cd roms and floppies so i am logged in as root what i want to do is mount the following drives drive 1 ide partition 2 drive 2 to 5 seen... (2 Replies)
Discussion started by: davidjk
2 Replies

10. UNIX for Dummies Questions & Answers

Complete Newbie Question

I am in a test environment where i need to test several versions of UNIX, such as linux, solaris, SCO (ODT and Unixware). What i would like to know is there a universal way to work with the contents of a floppy diskette? I know some give you dos-like commands, but am looking for a way to access and... (1 Reply)
Discussion started by: Dpinion
1 Replies
Login or Register to Ask a Question