LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2012, 12:43 PM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
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?
 
Old 03-02-2012, 12:50 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
This will replace :2 with :02 in the first line of the file.
Code:
sed -i '1 s/:2/:02/' file.name
 
Old 03-02-2012, 01:04 PM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
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]
 
Old 03-02-2012, 01:38 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,255

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Same solution but save the data:
Code:
sed -ri 's/:([1-9])$/:0\1/' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] head -n -1 (sed -n -e '1,$-1p' is incorrect) sed question, as stupid as it could be. kaz2100 Programming 1 12-27-2011 10:18 PM
[SOLVED] Question about sed command rbalaa Linux - Software 11 11-25-2011 11:07 AM
[Solved] Problem - question for command inside sed. logar0 Linux - Newbie 10 10-25-2010 12:41 PM
sed command question mokku Linux - Newbie 2 03-05-2008 12:30 PM
question about using sed command feetyouwell Linux - Software 4 12-13-2004 09:47 AM


All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration