Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk or sed - replace wildcards 2

Status
Not open for further replies.

neuralnode

Technical User
Sep 12, 2007
59
PL
Hi All,

I want to replace a string with a wildcard and a regular expression on a Solaris 10 system. This is what I attempted:

awk '{sub(MaxAuthTries*[0-9]/, "MaxAuthTries 5");print}' /etc/ssh/sshd_config

but it failed with the following error:

awk: syntax error near line 1
awk: illegal statement near line 1


So my question is: how can I accomplish this feat?

As you can see, what I'm trying to do is to replace the string, e.g. "MaxAuthTries 8" with "MaxAuthTries 5". Because the number can be anything, I need to use regular expression that would tell to replace any numeric character.

Your advice is appreciated!
Thanx in advance.

 


In Solaris you may need to use gawk:
Code:
gawk '{sub([red]/[/red]MaxAuthTries*[0-9]/, "MaxAuthTries 5");print}' /etc/ssh/sshd_config
And you need an extra slash ("/")..
[3eyes]




----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
[!]n[/!]awk '{sub([!]/[/!]MaxAuthTries[!][ \t][/!]*[0-9]/, "MaxAuthTries 5");print}' /etc/ssh/sshd_config


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanx guys for help!

I used PHV's suggestion, as gawk is not installed on my box.
At the same time I found that sed also works, although earlier it didn't (it really baffles me why now it does, maybe i made some typo before).

FYI, the sed version would be:

sed 's/MaxAuthTries [0-9]/MaxAuthTries 5/g' /etc/ssh/sshd_config

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top