- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: replacing just one specific occurance in file
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
Forums
Discussions
Discussions
Discussions
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
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
03-07-2002 01:53 AM
03-07-2002 01:53 AM
how do I replace just the first LPC=10 to LPC=40
and not the second or further occurances?
Thanks,
Bill!
[ Isup_SS7_Platform ]
LPC=10, classname=SS7_Stack_1, MtpProtocol=ITU, IsupProtocol=ITU
[Isup_Dpc_10_20]
LPC=10
DPC=20
~
~
~
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 01:55 AM
03-07-2002 01:55 AM
Re: replacing just one specific occurance in file
a: specific change
b: adding 30
It's possibly better to just change to
LPC=101
by adding a 1 to the end of what's in the file originally and the format can be different.. ie not always a decimal number.
Thanks,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 01:58 AM
03-07-2002 01:58 AM
Re: replacing just one specific occurance in file
# cat file | sed -e 's/LPC=10,/LPC=40,/'
I know I am cheating but hey, it works :P
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 02:01 AM
03-07-2002 02:01 AM
Re: replacing just one specific occurance in file
Forgot to add, try using the comma (,) to advantage.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 02:06 AM
03-07-2002 02:06 AM
Re: replacing just one specific occurance in file
/usr/bin/sed -e "s|^$key=$LPC|$key=$value|" $filename > $TMP_WORKFILE
where key=LPC
LPC=10
value=${LPC}1
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 02:17 AM
03-07-2002 02:17 AM
SolutionTry:
/usr/bin/sed -e "1,/$LPC/s|^$key=$LPC|$key=$value|" $filename > $TMP_WORKFILE
This will stop replacing once it's found the 1st occurrence.
The g switch is for replacing all occurrences in *each* line.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 02:21 AM
03-07-2002 02:21 AM
Re: replacing just one specific occurance in file
(Back into a scripting week, hope the forums stay online!)
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 04:39 AM
03-07-2002 04:39 AM
Re: replacing just one specific occurance in file
Using the sample you provided, only the first occurrence of LPC=10 has a comma after it. Thus, using the comma will work for your sample above.
However from your response, I gather that the second occurrence of LPC=10 in your full text actually has a comma tagging after it. If that is the case, then using the comma to differentiate the first occurrence from the rest in my method will not work.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 04:41 AM
03-07-2002 04:41 AM
Re: replacing just one specific occurance in file
That works fine too.
Later,
Bill