LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-21-2013, 05:50 AM   #1
ahsanpmd
LQ Newbie
 
Registered: Oct 2012
Posts: 28

Rep: Reputation: Disabled
Exclamation Using sed command


I want to replace ydate_ini='2013022000' with ydate_ini='$DATE00' (where DATE is system's date) in a file using sed.

Tried cat INPUT | sed "s/^.ydate_ini.*$/ ydate_ini='$DATE00'/" > INPUT.new

but now working.
 
Old 02-21-2013, 06:52 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Code:
# create date
 t=`date +%Y%m%d`
 echo $t
20130221


 cat t.t
ydate_ini='2013022000'

 sed -i -e "s:^ydate_ini.*:ydate_ini='${t}00':" t.t
 cat t.t
ydate_ini='2013022100'
-i flag does in-place replacement, so backup the file first.
 
Old 02-21-2013, 07:56 AM   #3
ahsanpmd
LQ Newbie
 
Registered: Oct 2012
Posts: 28

Original Poster
Rep: Reputation: Disabled
Thanks chris atually I was making a mistake in my command , thanks For your help too
 
Old 02-21-2013, 11:11 PM   #4
ahsanpmd
LQ Newbie
 
Registered: Oct 2012
Posts: 28

Original Poster
Rep: Reputation: Disabled
Your command not working Chris
In my file INPUT there is line ydate_ini='2013022000', ydate_bd='2013022000',
I have to change both ydate_ini and ydate_bd with current date. Your command isn't making any effect.However I have used
cat INPUT | sed "s/^.*ydate_ini=.*$/ ydate_ini='$DAY'/" > INPUT.new
It changes ydate_ini to current date but it omit the next portion of the line i.e ydate_bd='2013022000',
 
Old 02-21-2013, 11:23 PM   #5
ahsanpmd
LQ Newbie
 
Registered: Oct 2012
Posts: 28

Original Poster
Rep: Reputation: Disabled
it worked
cat INPUT | sed "s/^.*ydate_ini=.*$/ ydate_ini='$DAY', ydate_bd='$DAY',/" > INPUT.new
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed gives :sed: -e expression #1, char 1: unknown command: `'' samasat Linux - Newbie 10 06-09-2012 06:31 PM
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 01:27 PM
Sed command - command garbled errror gauavmahesh Linux - Newbie 3 03-30-2012 11:04 PM
Modifying text file with "one command line" SED command... daleo Linux - Newbie 3 01-13-2012 06:32 AM
sed Command linuxdev Linux - Newbie 3 02-09-2004 12:27 PM


All times are GMT -5. The time now is 11:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration