General discussion

Locked

Pattern search and replacement in shell

By rbwillba ·
I am helping to set up a production AIX UNIX box in my shop. We have several SAS scripts that will be running monthly and will need monthly changes to their code. The SAS code is in the form of a text file, so I think we will be able to accomplishthese changes using a shell script. I know I can locate the patterns that need changing using awk, but I have not come across anything that will replace them for me once found. There must be a way, and I'm sure it's not difficult. 200 easy tech points to anyone who can set me up with a solution. -Thanks

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Pattern search and replacement in shell

by Stephen Darlington In reply to Pattern search and replac ...

Use the right tool for the job!

If you want to replace one string literal with another, sed will do the trick, e.g.

sed 's/this/that/' < in > out

sed also does regular expressions, but it can get complicated very quickly. (What does 's/Acct#\([0-9]*\)/\1/' do? Answers on a postcard...)

You can do similar tricks with awk (same command). The main advantage is that you can remember fields from previous lines more easily.

Remember, Unix In A Nutshell is your friend.

And don't forget Perl or Python if it's more complicated than that.

Collapse -

Pattern search and replacement in shell

by rbwillba In reply to Pattern search and replac ...

Poster rated this answer

Collapse -

Pattern search and replacement in shell

by rbwillba In reply to Pattern search and replac ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums