LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2012, 01:56 AM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Rep: Reputation: Disabled
Angry Help needed in SED utilty


Hi All,
Please help me out in sed..

iam writing one script in that i want to replace som content with the variable value but its not working for me...can you please suggest what can i do here...

Snippet of code is:

sed -i "s/from_date=..\/.*\/..../from_date=$var" filename

cat filename
No changes in file
from_date is not updating in file.
 
Old 11-16-2012, 02:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by azheruddin View Post
Snippet of code is:

sed -i "s/from_date=..\/.*\/..../from_date=$var" filename

cat filename
No changes in file
from_date is not updating in file.
without knowing what the input looks like it is hard to help you with the regex, but I do notice a missing /:
Code:
sed -i "s/from_date=..\/.*\/..../from_date=$var" filename
vs
sed -i "s/from_date=..\/.*\/..../from_date=$var/" filename
BTW: You can use any separator you want in sed, which makes thing more readable and removes the need to escape certain characters:
Code:
sed -i "s%from_date=../.*/....%from_date=$var%" filename
 
Old 11-16-2012, 04:43 AM   #3
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
seed utilty

druuna,

will explain you my exact query

in my file1 there is field named from_date=12/11/2012

so i want to update the from_date field through variable using sed utility and format should not be changed.

Sorry to say but the missing snipet you have pointed ,corrected that one still not working here..

Hope you understood the issue!
 
Old 11-16-2012, 04:50 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
This works on my box:
Code:
$ var=$(date '+%F')
$ echo $var
2012-11-16
$ cat infile
field named from_date=12/11/2012 and possible other stuff
$ sed "s%from_date=../../....%from_date=$var%" infile
field named from_date=2012-11-16 and possible other stuff
If that doesn't work: Post your input file and the content of var.
 
Old 11-16-2012, 05:01 AM   #5
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Sorry to say but i have a dependency like ....date format should be like 12/11/2012
and it should be update in same format as its in variable...
 
Old 11-16-2012, 05:09 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by azheruddin View Post
Sorry to say but i have a dependency like ....date format should be like 12/11/2012
and it should be update in same format as its in variable...
That is not a sed problem, that is just the content of your var variable....
Code:
$ var=$(date '+%d/%m/%Y')
$ echo $var
16/11/2012
$ sed "s%from_date=../../....%from_date=$var%" infile
field named from_date=16/11/2012 and possible other stuff
 
Old 11-18-2012, 10:02 PM   #7
azheruddin
Member
 
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Smile

Thak You very Much Its Really worked out for me!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Help needed(Sed) pinga123 Linux - Newbie 3 06-22-2010 12:46 PM
sed help needed ZAMO Linux - General 7 01-09-2009 07:58 AM
sed help needed avijitp Programming 8 11-19-2007 09:33 AM
SED help needed DriveMeCrazy Linux - General 2 11-20-2006 11:04 PM
network utilty? mchitrakar Linux - Networking 4 04-22-2004 10:25 AM


All times are GMT -5. The time now is 05:32 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration