LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about sed command. (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-sed-command-932367/)

xeon123 03-02-2012 11:43 AM

Question about sed command.
 
Hi,

I've this 2 line in a file:

Code:

00:02:2
00:02:34

and I want to use the sed command to replace to:


Code:

00:02:02
00:02:34


How do I do that with sed command?

weibullguy 03-02-2012 11:50 AM

This will replace :2 with :02 in the first line of the file.
Code:

sed -i '1 s/:2/:02/' file.name

xeon123 03-02-2012 12:04 PM

But it could be any number from [1-9].

For example:
[code]
00:01:1
00:02:2
00:03:5
00:04:9
00:02:34
00:05:49
00:10:24
[\code]

grail 03-02-2012 12:38 PM

Same solution but save the data:
Code:

sed -ri 's/:([1-9])$/:0\1/' file


All times are GMT -5. The time now is 10:42 AM.