Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to clean up a log file for better readability - there's a load of un-necessary stuff there to my needs - i basically have to replace sshd[xxxx] where xxxx is an arbitrary number with, well, either a space or nothing. While i can replace a known string, i have no idea how to do a sed wildcard in this case- So- how do i do that?

share|improve this question
up vote 1 down vote accepted

its not clear whether you want the replace the "sshd" as well, so i assumed you it is.

   sed 's/sshd\[[0-9]*\]//g' file


   sed 's/sshd\[[0-9]*\]/sshd[]/g' file
share|improve this answer
the first one was what i was looking for, thanks :) – Journeyman Geek Mar 19 '10 at 6:37

You are looking to replace all numbers after sshd inside [] with nothing. To select numbers you can use a range [0-9]\+, where [0-9] matches any digit and \+ means one or more of that before.

So for your case the regexp to replace numbers with zeros would be

sed -r s/\[[0-9]\+\]/\[\]/

where the -r enables extended regexp's like the one above. The \[ and \] are just to escape the [ and ] so they don't get interpreted by sed.

For regexp operators like \+ have a look at this section in the gawk manual, for character list like [0-9] see this section -- most of what you see there applies to sed as well.

share|improve this answer
shouldn't it be sed -r s/\[[0-9]\+\]/\[\]/, in order to keep the [] without the number? – Snark Mar 19 '10 at 6:26
@snark you're right – Benjamin Bannier Mar 19 '10 at 6:56
You can omit the -r if you quote the command. If you do both (use -r and quote the command), you can omit the escaping of the +. sed 's/\[[0-9]\+\]/\[\]/' or sed -r 's/\[[0-9]+\]/\[\]/' Often, when there are grouping parentheses, using -r with quoting can save several characters and improve readability since the parentheses don't need to be escaped. – Dennis Williamson Mar 19 '10 at 9:08
@Dennis interesting – Benjamin Bannier Mar 19 '10 at 12:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.