- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Shell Script Help
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
тАО02-24-2006 01:19 AM
тАО02-24-2006 01:19 AM
I have the following script:
sed -e 's/EMAIL_ADDR_TXT/AGENCY_LOCATION/'
-e 's/CONT_EMAIL_ADDR_TXT/AGENCY_CONTACT/'
-e 's/EMX_ADDR/WEB_APPLICANT/'
-e 's/SITE_EMAIL_ADDR_TXT/RESOURCE_LOCATION/' $BADMAIL>badmail1
but the result is all words of EMAIL_ADDR_TXT have been changed to AGENCY_LOCATION, the first sed choice.
I need some field protection and change the word to exactly what it means. But using [ ] to include words still not working. Nor I succeeds in using " " to protect.
Any comments are appreciated.
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 01:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 01:32 AM
тАО02-24-2006 01:32 AM
Re: Shell Script Help
You need to provide a better regular expression -- one that uniquely identifies the boundries of a match/substitution.
For example, anchor EMAIL_ADDR_TXT to the beginning of a line with a caret:
sed -e 's/^EMAIL_ADDR_TXT/
You can anchor at the end of a line with a dollar sign ($). You can use spaces and tabs too to form logical boundries.
Far, far superior to 'sed' is 'perl'. Perl has some of the very best regular expression support you can find, in my opinion.
Regards!
...JRF...
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 01:37 AM
тАО02-24-2006 01:37 AM
Re: Shell Script Help
I guess you need to use the global option (/g) option, just like in vi :%s/
So the syntax would be:
sed -e 's/EMAIL_ADDR_TXT/AGENCY_LOCATION/g'\
-e 's/CONT_EMAIL_ADDR_TXT/AGENCY_CONTACT/g'\
-e 's/EMX_ADDR/WEB_APPLICANT/g'\
-e 's/SITE_EMAIL_ADDR_TXT/RESOURCE_LOCATION/g'\
$BADMAIL>badmail1
Cheers,
Renarios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 01:57 AM
тАО02-24-2006 01:57 AM
Re: Shell Script Help
A very good reading about "sed"
http://www.student.northpark.edu/pemente/sed/sed1line.txt
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 03:10 AM
тАО02-24-2006 03:10 AM
Re: Shell Script Help
as a first change, you could change the order of the sed-commands: since the command sequence of sed is in serial order, put the longest strings first: they have been changed already when sed executes the following command(s).
sed -e 's/CONT_EMAIL_ADDR_TXT/AGENCY_CONTACT/'
-e 's/SITE_EMAIL_ADDR_TXT/RESOURCE_LOCATION/'
-e 's/EMAIL_ADDR_TXT/AGENCY_LOCATION/' ...
If there is always at least one character of text before the search pattern, you can anchor it (like the other posters suggested). Pattern starting at the beginning of a line must be added seperately:
sed -e 's/\([^_]\)EMAIL_ADDR_TXT/\1AGENCY_LOCATION/' -e 's/^EMAIL_ADDR_TXT/AGENCY_LOCATION/'
..
and so on. If the overlapping search pattern differ not in the '_' unterline, the anchor pattern has to be refined, perhaps you need a different anchor pattern for the end of the search pattern.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 03:13 AM
тАО02-24-2006 03:13 AM
Re: Shell Script Help
I'm not sure if your question has been answered by one of the aforementioned posts, but it'll help if you could attach a portion of the input file on which these sed substitutions have to occur. These would definitely help in providing an accurate solution to your problem.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 03:15 AM
тАО02-24-2006 03:15 AM
Re: Shell Script Help
try:
sed -e 's/SITE_EMAIL_ADDR_TXT/RESOURCE_LOCATION/'
-e 's/CONT_EMAIL_ADDR_TXT/AGENCY_CONTACT/'
-e 's/EMX_ADDR/WEB_APPLICANT/'
-e 's/EMAIL_ADDR_TXT/AGENCY_LOCATION/' $BADMAIL>badmail1
Since Sed exceutes the commands in order, first chnage the long pattern and after the pattern contained into previous pattern already chnaged.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 03:57 AM
тАО02-24-2006 03:57 AM
Re: Shell Script Help
Thanks a lot and have fun.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 04:04 AM
тАО02-24-2006 04:04 AM
Re: Shell Script Help
What exactly you want to do ? Its always better to use perl for regular expressions.
http://www.english.uga.edu/humcomp/perl/regex2a.html
-Arun