- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: replacing according to position
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 10:21 PM
тАО04-08-2007 10:21 PM
can anybody help in this
In a line, i have a pattern tat is to be replaced.
using sed , i can replace in a particular line, but tat pattern can occur in the line in many other places.
i want only one instance to be replaced.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 10:26 PM
тАО04-08-2007 10:26 PM
Re: replacing according to position
I want the 2nd instance of Blore to b replaced in 2nd line.
But in the actual file am not sure of the occurance of this instance.It can be 3rd instance.
But the position is fixed.
so in this case, 23-27 characters in 2nd line to be replaced by Mlore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 10:28 PM
тАО04-08-2007 10:28 PM
Re: replacing according to position
One instance per line, or one per whole file?
For the former, don't add "g" to the "s" function, then it only will replace one.
If it is once per file, you'll need to write an awk script. To replace to the first then copy the rest of the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 10:48 PM
тАО04-08-2007 10:48 PM
Re: replacing according to position
Can u give me a solution for my attached file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 11:18 PM
тАО04-08-2007 11:18 PM
Re: replacing according to position
In the vi editor, can you try this:
:1,$s/.Blore/Mlore
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 11:33 PM
тАО04-08-2007 11:33 PM
Re: replacing according to position
You may need to quote the "." otherwise it would match the first:
:1,$s/\.Blore/Mlore
(But I guess it was safe since there are no chars before the first Blore.)
>But the position is fixed. so in this case, 23-27 characters in 2nd line to be replaced by Mlore
That makes it easy:
sed -e 's/^\(......................\)Blore/\1Mlore/'
(There should be 22 dots. The \1 puts them back into the output. If only one the second line, you can use '2s/'.)
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2007 11:50 PM
тАО04-08-2007 11:50 PM
SolutionA bit more readable (and much easier to maintain) is the specificatino of the number of character repetitions, thusly:
# sed -e 's/^\(.\{22\}\)Blore/\1Mlore/'
Note that the curly braces must be escaped with a backslash just like the parentheses must be.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2007 04:49 PM
тАО04-09-2007 04:49 PM
Re: replacing according to position
Thanks a lot for the help.
One more query is that,
is ther any restriction on the no. of characters?
I mean.. in a line can i change the 260-264th character in the similar manner?
I hav to achieve that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2007 04:57 PM
тАО04-09-2007 04:57 PM
Re: replacing according to position
No, you can use JRF's improvement, and you just type in the number.
^\(.\{259\}\)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2007 05:04 PM
тАО04-09-2007 05:04 PM
Re: replacing according to position
Didnt get JRF`s improvement???