Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Wondering what the fastest way would be to strip the text from just some delimited fields in a list.

My list looks like this:
text text:number:text:text:text:text:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*

And I want it to look like this:
text text:*:*:*:*:text:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*

So some fields that have data need to be replaced by asterisks, some fields need to be untouched, and the delimiter isn't consistent (first and second field separated by spaces). This is on a linux filesystem and a way to do it inline on the file is preferred.

Thanks much for the help!

share|improve this question

I would use a regular expression that matches your text (parentheses capture text into buffer designated by \1, \2, etc):


and a replacement regular expression:


with sed:

sed 's/matching-regularexpression/replacement-regular-expression/' name-of-text-file

You may have to fiddle with escape characters a little depending on your shell.

share|improve this answer
don't forget sed -f <sedscript> if you've got multiple changes to make.... – Greeblesnort Sep 19 '09 at 4:37

I'd probably do it in perl:

perl -pi.bak -e 's/^(\w+\s\w+):\d+:\w+:\w+:\w+:(.*)/$1:$2/' FILENAME

share|improve this answer

Your Answer


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