2

Let's say I have this output:

0001
0002
0003
0004
0005

and I want to replace the first two zeros (00) with (01). What is the simplest way to achieve this?

1 Answer 1

5

Something like this will do:

$ sed 's/^00/01/' file.txt

Details

The above will look through each line of file file.txt and replace any occurrences of 00 that are anchored to the beginning of the line (that's what the caret, ^, does). For each occurrence it will be replaced with 01.

The function I'm using within sed is called search and replace (s/../../).

1
  • 1
    You're right, I've removed my post and upvoted yours.
    – Vinz
    Oct 28, 2013 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .