- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed: replace exact string (upper and lower cases)
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
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
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
05-26-2014 02:28 PM
05-26-2014 02:28 PM
hello,
i have a file ( parameter file of a database. filename: init.ora). the string length of the database sid are 4 characters.
database sid name is : INTE . i want to replace the sid name to a new sid name. i have combinations like:
- INTE_inte or INTE or /INTE/ # comment
- but there are some strings like: query_rewrite_integrity ... this string also include "inte" , but this string i don't want to replace !
so i search for the string "INTE" or "inte"
grep -E "INTE[^A-Z]|INTE$|inte[^a-z]|inte$" init.ora
old replacement was ( not exact)
sed -e "s|INTE|AAAA|g" -e "s|inte|aaaa|g"
but this statement works with Linux "sed" and not with HP-UX "sed" and didn't the right output:
sed -e "s/INTE\([^A-Z]\|$\)/AAAA\1/" -e "s/inte\([^a-z]\|$|\)/aaaa\1/" init.ora
are there any alternatives ? an example file is in the attachments, but you have to rename from init_ora.txt to init.ora
kind regards
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2014 10:26 PM
05-26-2014 10:26 PM
Solution>are there any alternatives?
You're trying to use sed with EREs. Instead repeat the script twice for each:
sed -e 's/INTE\([^A-Z]\)/AAAA\1/g' \
-e 's/INTE$/AAAA/' \
-e 's/inte\([^a-z]\)/aaaa\1/g' \
-e 's/inte$/aaaa/' \
init.ora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2014 11:54 PM
06-10-2014 11:54 PM
Re: sed: replace exact string (upper and lower cases)
in the meantime i got support of a perl programer
perl -p -e 'while (/INTE/gi) { if (substr($_,$+[0]) !~/=/ && substr($_,0,$-[0]) !~/#/) { s/INTE/INUA/; s/inte/inua/; } }' init.ora
the usage in a shell script will be ( i didn't a better solution) :
STRING_ACT="INUA" STRING_OLD="INTE" CHANGE_FILE="init.ora" STRING_OLD_LOW=$(echo ${STRING_OLD} | tr '[:upper:]' '[:lower:]') STRING_ACT_LOW=$(echo ${STRING_ACT} | tr '[:upper:]' '[:lower:]') P_STRING_ACT="${STRING_ACT}" \ P_STRING_OLD="${STRING_OLD}" \ P_STRING_OLD_LOW="${STRING_OLD_LOW}" \ P_STRING_ACT_LOW="${STRING_ACT_LOW}" \ perl -i -p -e 'while (/$ENV{P_STRING_OLD}/gi) { if (substr($_,$+[0]) !~/=/ && substr($_,0,$-[0]) !~/#/) { s/$ENV{P_STRING_OLD}/$ENV{P_STRING_ACT}/; s/$ENV{P_STRING_OLD_LOW}/$ENV{P_STRING_ACT_LOW}/; } }' ${CHANGE_FILE
i mean, the "sed" is easier to read.
- Tags:
- Perl