- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed / awk replace
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
тАО05-04-2009 11:19 AM
тАО05-04-2009 11:19 AM
I have a string in a template, I want to build a date query into..
The original string is below:
COMPLETE_DATE&SMON=04&SDAY=30&SYEAR=2009&EMON=04&EDAY=30&EYEAR=2009
I have a template with that entry in. I want to use this template to do a search/replace string based on standard unix date for "today"
ie:
SMON and EMON = `date +%m`
SDAY and EDAY = `date +d`
SYEAR and EYEAR = `date +Y`
can someone show me the reg expression on which characters I'd need to escape? I am guessing the & and = need escaped, Any other ideas on what I could do?
I appreciate it.. Rex M
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2009 12:50 PM
тАО05-04-2009 12:50 PM
Re: sed / awk replace
What the template do you want to replace?? What portion of the string noted should be replaced, as you're getting strings of numbers, so I guess they need to go on the right side of the equals.
something like COMPLETE_DAT&SMON=$SMON.... perhaps?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2009 12:59 PM
тАО05-04-2009 12:59 PM
Re: sed / awk replace
The "main file" is a php curl I am needing to cron a query at night against a website/database..
If I use a copy of the original the "date" is in one location in the file:
COMPLETE_DATE&SMON=04&SDAY=30&SYEAR=2009&EMON=04&EDAY=30&EYEAR=2009
I need to replace "04", "30", "2009" with the actual unix system date in a sed replace of the COMPLETE DATE
I need to REPLACE the dates in the COMPLETE_DATE and replace it with
day=`date +%d`
month=`date +%m`
year=`date +%Y`
I can call the PHP script as a subshell, but I need to edit the script prior to running it so the date is current.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2009 07:34 PM
тАО05-04-2009 07:34 PM
SolutionCOMPLETE_DATE&SMON=04&SDAY=30&SYEAR=2009&EMON=04&EDAY=30&E
YEAR=2009
(I would think if you had a template you would have MM, DD and YYYY instead of actual numbers?)
>I am guessing the & and = need escaped,
Just "&", "=" isn't special.
MM=$(date +%m)
DD=$(date +%d)
YYYY=$(date +%Y)
sed -e "s/\&SMON=04/\&SMON=$MM/" -e "s/\&EMON=04/\&EMON=$MM/" \
-e "s/\&SDAY=30/\&SDAY=$DD/" -e "s/\&EDAY=30/\&EDAY=$DD/" \
-e "s/\&SYEAR=2009/\&SYEAR=$YYYY/" -e "s/\&EYEAR=2009/\&EYEAR=$YYYY/" file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2009 09:09 PM
тАО05-04-2009 09:09 PM
Re: sed / awk replace
So would I, but what do I know?
> [...] & and = need escaped [...]
For my information only, are you from
Missouri, or is there someplace else where
someone would not say "need to be escaped"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2009 01:46 AM
тАО05-05-2009 01:46 AM
Re: sed / awk replace
to print this out you could just use the date command with custom formatting like this:
# date +"COMPLETE_DATE&SMON="%m"&SDAY="%d"&SYEAR="%Y"&EMON="%m"&EDAY="%d"&EYEAR="%Y
COMPLETE_DATE&SMON=05&SDAY=05&SYEAR=2009&EMON=05&EDAY=05&EYEAR=2009
Unix operates with beer.
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2009 01:54 AM
тАО05-05-2009 01:54 AM
Re: sed / awk replace
# date +"COMPLETE_DATE&SMON="%m"&SDAY="%d"&SYEAR="%Y"&EMON="%m"&EDAY="%d"&EYEAR="%Y
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2009 05:02 AM
тАО05-05-2009 05:02 AM
Re: sed / awk replace
I got it working..
I just used a perl -pi -e replace.
I redefined the string in the template to readable BASEMONTH, BASEDAY, BASEYEAR then defined the variables to replace the information in the RUN file from the template.
export day=`date +%d`
export month=`date +%m`
export year=`date +%Y`
cp class_curlConnect.php.template class_curlConnect.php
perl -pi -e s/BASEMONTH/${month}/g class_curlConnect.php
perl -pi -e s/BASEDAY/${day}/g class_curlConnect.php
perl -pi -e s/BASEYEAR/${year}/g class_curlConnect.php
- Tags:
- Perl