0

INPUT

RANDOMSTRING BLA-BLA [111] RANDOMSTRING BLA-BLA

OUTPUT

RANDOMSTRING BLA-BLA [200] RANDOMSTRING BLA-BLA

[111] could contain various numbers with 3 digits: 120 or 300 or 400 or 101, etc.

So all I want ~this:

sed "s/Howtos<\/a> \[111] \//`grep '^<a href="' list.txt | wc -l`/" original.txt

"Regexp'ing the 111" that's the only thing I can't figure out

The output of:

grep '^<a href="' list.txt | wc -l

would be e.g.: 200 in the example

2
  • I'm not sure if this is a typo or not, but I think you need to escape both the opening [ and the closing ], if you want those literal chars. Commented May 8, 2011 at 19:32
  • I cannot make out what you are trying to accomplish here. Do you want to rip out the 3 digit numbers for use in something? Do you want to replace them with something else? Is it possible that digits could appear in the random strings before and after the one you want to work with? Are the fields consistent (e.g. Is it always the third space separated item from the left of the string?) Commented May 9, 2011 at 9:19

1 Answer 1

2

regex for 3 digit number: [0-9]{3} So to replace 111 with 200:

sed -E 's/[0-9]{3}/200/g'

you need the -E flag for extended regexs

4
  • Do most versions of sed now support {3}? I was going to suggest \[[0-9][0-9][0-9]\], but it would be nicer to be able to just use {3}. A quick follow-up GNU sed supports {3} if you pass the -r flag. I don't think BSD sed does. (At least OSX's sed doesn't seem to.) Commented May 8, 2011 at 19:29
  • 1
    use sed -E for extended regexs Commented May 8, 2011 at 19:32
  • Thank you but I choosed: [[0-9][0-9][0-9]] - because [0-9]{3} doesn't works even with -E :\ /Fedora14/Bash/ Commented May 8, 2011 at 19:35
  • 1
    @LanceBaynes If that's GNU sed, try -r instead of -E. (Aren't portability issues fun?) Commented May 8, 2011 at 19:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.