Unix - search and replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix - search and replace
# 1  
Old 03-16-2005
Unix - search and replace

Is it possible to do search and replace in unix
Like :

s/some date/current date/g

some date and current date both are in same format (dd/mm/yyyy hh:mm:ss)


My requirement is :
I am having a variable which holds last run date. After running my shell script I want to do update this variable with the current date.
# 2  
Old 03-16-2005
Code:
#!/bin/sh
eval "sed -n 's/[0-9]\{2\}\/[0-9]\{2\}\/[0-9]\{4\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}/`date '+%m\/%d\/%Y %H:%M:%S'`/gp' inputfile > outputfile"

# 3  
Old 03-17-2005
Thanks for the reply.

Also please if you suggest that :

In my shell script can i declare a variable (last_run_time) in the begining, Use this variable thru the code and before exiting the shell script update this variable with the code you supplied..



.... shell script start .....
last_run_time=16/03/2005 10:10:10
..
spool test
select * from table1 where creattion_date > $last_run_time;
spool off
..

****
Here i wanted to update the last_run_time variable (declared above) with the current date, so that the next time i run the script i shd get the records which are inserted after i last ran the query
****
.... shell script end .....




Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

3. UNIX for Dummies Questions & Answers

Help with search and replace or search only of / in vi

Hi all, I am editing a config file in vi that has a / on it. At the moment, search and replace looks alright as am able to use a # as a temporary separator, i.e. :,$s#/u01/app#/u02/app#g For doing a search, I have to escape the / do. So if I want to search for /u01/app, I am having to do... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

7. UNIX for Dummies Questions & Answers

Unix script, sed search and replace?

Hi, I am trying to write a shell script designed to take input line by line by line from a file with a word on each line for editing with sed. Example file: 1.ejverything 2.bllown 3.maikling 4.manegement 5.existjing 6.systems My design currently takes input from the user, and... (2 Replies)
Discussion started by: mkfitzwilliams
2 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

Help : Search and Replace

Hello, I'm lost on this one. I'm trying to search for a string in a file and replace it. But the string I'm searching for is on 2 seperate lines in the file and I only want to replace the 2nd occsrrance. This is what I know, but don't know how to select occurances that are on a seperate... (2 Replies)
Discussion started by: ctcuser
2 Replies
Login or Register to Ask a Question