- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: character replacemnt in a 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
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
тАО11-09-2006 03:18 AM
тАО11-09-2006 03:18 AM
Can someone help me in how to replace globally certain characeters in a file?
Ex: I have several lines looks like
abcd <1?
abcd <20>
abcd <5>
abcd <100>
I want to make abcd <5000> for all the occurance of abcd, the value in <> is different.
Thanks for your help.
Rajim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 03:25 AM
тАО11-09-2006 03:25 AM
Re: character replacemnt in a file
Open the file in vi editor
Go to command mode and
Then use the following the syntax
:$s/str1/str2/g
str1 ==>the string pattern to be replaced
str2 ==>The string which has to be there
Please make sure there is no space in the command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 03:31 AM
тАО11-09-2006 03:31 AM
Re: character replacemnt in a file
But str2 has different value on each occurence as you see in my example. Is there a way to use the wild card
abcd <*> for abcd <1> and abcd <20> etc...?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 03:55 AM
тАО11-09-2006 03:55 AM
Re: character replacemnt in a file
Then I would do this:
in vi mode type :
1,$s/abcd <.*>/abcd <5000>/g
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 03:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 04:01 AM
тАО11-09-2006 04:01 AM
Re: character replacemnt in a file
I wanted to explain what it means.
:1,$ is from line 1 to last line
the .* between < > means any character and any number of characters.
So that should fit <1> or <100> or <23000>
whatever , will be changed to <5000>
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 04:02 AM
тАО11-09-2006 04:02 AM
Re: character replacemnt in a file
I wanted to explain what it means.
:1,$ is from line 1 to last line
the .* between < > means any character and any number of characters.
So that should fit <1> or <100> or <23000>
whatever , will be changed to <5000>
You do not have to repeat the abcd, I
did that for clarity:
just the matching pattern which I hope
in your case is nicely between the < >
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 04:18 AM
тАО11-09-2006 04:18 AM
Re: character replacemnt in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 04:33 AM
тАО11-09-2006 04:33 AM
Re: character replacemnt in a file
The command you gave did not work. Here is the sample file.
I want to repalce everything in ()
Column1 varchar2 (1),
Column2 varchar2 (14),
Column3 varchar2 (6),
Column4 varchar2 (4000),
Column5 varchar2 (4000),
Column6 varchar2 (10),
Column7 varchar2 (4000),
Column8 varchar2 (16),
Column9 varchar2 (6),
Column10 varchar2 (28),
Column11 varchar2 (4),
Column12 varchar2 (9),
Column13 varchar2 (1),
Column14 varchar2 (4000),
Column15 varchar2 (3),
Column16 varchar2 (4),
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2006 06:04 AM
тАО11-09-2006 06:04 AM
Re: character replacemnt in a file
# sed 's/^\(Column[0-9]*\) \(varchar2\) ([0-9]*)/\1 \2 (5000)/p' file
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2006 05:58 PM
тАО11-12-2006 05:58 PM
Re: character replacemnt in a file
Sorry I was away for a long weekend.
I suspect you have your solution already,
but just to complete my answer to what
I would have done.
Yes, naturally I base my command on <>,
when replacing () it becomes a different
ballgame:
If you want to use it with round brackets,
do this:
1,$s!char2 (.*)!char2 (5000)!g
Just to illustrate the different effects:
If you just did
1,$s!(.*)!(5000)!g
It would replace the whole line with (5000).
The brackets are a bit special.