- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: find and replace yesterday's with todays date ...
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
тАО11-11-2008 01:38 AM
тАО11-11-2008 01:38 AM
find and replace yesterday's with todays date in sql file
I have sql file which contains one confition like:
OR ((n_works_notices.local_rec_date = "2008-11-11")
Everyday this date is replqced with today's date. For that i am using sed command:
sed -e 's/((n_works_notices.local_rec_date = ............/((n_works_notices.l
ocal_rec_date = "2008-11-11"/1' mysql.sql > temp.sql
Now i have new sql file which contains condition as
AND ("2008-11-08">=from_date) AND ("2008-11-08"<=to_date)
Now how to replace these to dates(2008-11-08) with todays date.
Everyday i have to find existing date and replace with today's date.
Can some one please help me?
Thanks
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 02:28 AM
тАО11-11-2008 02:28 AM
Re: find and replace yesterday's with todays date in sql file
You can store current date into a variable and use this variable where you need current date see the below example:
$ dt=`date +%Y"-"%d"-"%m`
$ echo $dt
2008-11-11
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 02:45 AM
тАО11-11-2008 02:45 AM
Re: find and replace yesterday's with todays date in sql file
I am doing same. But can you please show the complete sed statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 08:02 AM
тАО11-11-2008 08:02 AM
Re: find and replace yesterday's with todays date in sql file
The problem is how to compute yesterday.
The simplest way is to start with a template file where you don't have yesterday but you have a template: YYYY-MM-DD
Then you just have a sed command that changes that to today:
$ dt=$(date +%Y-%d-%m)
$ sed "s/YYYY-MM-DD/$dt/g" template.sql > temp.sql
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 08:51 AM
тАО11-11-2008 08:51 AM
Re: find and replace yesterday's with todays date in sql file
Look for something like "date('today')" in your implementation. In addition, you might need to fiddle the date format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 11:18 PM
тАО11-11-2008 11:18 PM
Re: find and replace yesterday's with todays date in sql file
I was just thinking of idea to find pattern like YYYY-MM-DD in sql and replacing with current date.
Can you sugget how to write pattern and dates following this pattern will be getting changed.
It means it if it fileds date in statement :
OR ((n_works_notices.local_rec_date = "2008-11-11")
it will update to current date.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 11:41 PM
тАО11-11-2008 11:41 PM
Re: find and replace yesterday's with todays date in sql file
I'm suggesting you use EXACTLY that string and change it every time you need it.
I suppose you could look for DDDD-DD-DD (D is a digit) but why bother?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2008 03:18 AM
тАО11-12-2008 03:18 AM
Re: find and replace yesterday's with todays date in sql file
Thanks a lot.
Looks it will help.
Thanks