- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Strings replacement help needed
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-24-2009 03:53 AM
тАО04-24-2009 03:53 AM
I have to replace a string in a file of 1000 lines. That string is distributed and i want to replace only 200 lines out of 1000 lines of that particular strings.
It should be in interactive mode where i can get the information before replacing that string.
Thanks in advance.
Waiting for the earliset response.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 04:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 05:04 AM
тАО04-24-2009 05:04 AM
Re: Strings replacement help needed
in this case I'd use vi.
to search:
/
then "n" to locate the next occurance
method of replacement is going to vary depending on if its a 'word', or exactly the same length or buried in some longer string...
insuffficient information for a complete answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 05:49 AM
тАО04-24-2009 05:49 AM
Re: Strings replacement help needed
The Perl script I suggested replaces up to 200-lines regardless of how many matches occur per line.
It is trivial to modify the substitution to "words" or simply any string sequence as I used.
I agree that more information would lead to a more complete answer.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 06:04 AM
тАО04-24-2009 06:04 AM
Re: Strings replacement help needed
James.....
Thank you so much. Its working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 06:32 AM
тАО04-24-2009 06:32 AM
Re: Strings replacement help needed
as "I need to see it in context before confirming change"...which apparently isn't the case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 06:37 AM
тАО04-24-2009 06:37 AM
Re: Strings replacement help needed
can it be done in interactive mode?
Do u have any alternatives?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 06:56 AM
тАО04-24-2009 06:56 AM
Re: Strings replacement help needed
No, I made no provisions for doing this "interactively". I find it hard to imagine why you want to replace 200 of 1000 lines "interactively", which to me suggests confimation as you proceed. If this is true, do you count a line toward the "200" if you reject its change or only if you accept it?
Since I left the input file un-modified, I felt that this was an adequate "interactive" preview step in and of itself. Re-running the script after inspecting the results would then only require a simple redirection to a new output file or the change of the Perl swithes from '-pe' to '-pi -e' to affect an in-place update.
I interpreted your original question to mean _lines_ on which substitutions occur regardless of how many _times_ per line a substitution was made. How would that factor into your count toward "200" if you were to ask for confirmation at each step?
What is the problem you really want to solve? If it isn't an on-going one, using 'vi' as Oldschool suggested might be the fastest solution.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2009 11:07 PM
тАО04-26-2009 11:07 PM
Re: Strings replacement help needed
I have to use VI and a lot of patience.
Find the string (/) and replace it (r), find next occurrence (n) and replace it (.) and so on.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2009 11:16 PM
тАО04-26-2009 11:16 PM
Re: Strings replacement help needed
You can also use:
:first,last s/string1/string2/gc
The "c" asks you to confirm for each line.