how can the search and replace can be done interactively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how can the search and replace can be done interactively
# 1  
Old 06-03-2008
how can the search and replace can be done interactively

hi,

To search and replace a string in multiple files i am using following command:
find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find_string/replace_string/g'

I want to be prompted while replacing the string.
how this can be done.

thanks for every help.
# 2  
Old 06-03-2008
In theory, simply replace the Perl script with one which prompts you for each substitution. In practice, for usability reasons, you would probably want to use the search and replace features of an editor, and simply feed the editor with a simple script. That way, you get undo, a nice way for the user to see the wider context of each change, and of course, the ability to make unrelated edits when you see something which needs fixing, etc. I personally recommend Emacs, but whatever editor you, or your users, are familiar with should do (unless it's too GUIey for its own good ...).
# 3  
Old 06-04-2008
thanks.
yes, replacing it with an interactive perl script has solved the issue.
the other suggestion would certainly help in a broader context.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. HP-UX

how to run top or glance non-interactively using ssh

Hello Am trying to run top /glance non-interactively using ssh from redhat to hp-ux hosts but getting following errors.. ======================= ssh msi 'top -n 1' Sorry, I need to know a more specific terminal type than "unknown". ssh msi top -d1 -n20 > /tmp/top.out Sorry, I need... (3 Replies)
Discussion started by: delphys
3 Replies

3. 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

4. Shell Programming and Scripting

input username and password interactively

Hi guys, I am using Solaris 10 and we install IBM OnDemand server there. there's a command called arsload that we use to load document and query document too. I need to write a script to query document but when querying document, this command prompt for username then password. My question is... (3 Replies)
Discussion started by: markthien
3 Replies

5. 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

6. Shell Programming and Scripting

How to remove a cron job interactively?

My application has r.cron file which removes the cron job automatically during un-installation (pkgrm). But I want to take user input to decide on the deletion of cron job. I tried to put the code (to prompt user) in r.cron itself. But it is not waiting for user input. Where can I put that code? We... (0 Replies)
Discussion started by: durbam2002
0 Replies

7. UNIX for Advanced & Expert Users

Copy interactively - shell input

Hello, I am making a script to copy files interactively from one directory to another using the "i" option because I dont want to overwrite the files. cp -i *.html ./../otherdir/ cp: do you want to overwrite (y/n) ? I used cp -i *.html ./../otherdir/ ans='n' read $ans ... (4 Replies)
Discussion started by: telecomics
4 Replies

8. UNIX for Dummies Questions & Answers

Zip and password protect non-interactively

I'm wondering if there is a way to zip a file and password protect it non-interactively. zip -e will prompt for a password but I don't want a prompt. This needs to be done automatically as part of a shell script. I'm using the zip command because the will be unzipped by a Windows machine. ... (1 Reply)
Discussion started by: savage66
1 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Retrieving output interactively

Hi. I have a situation where I need to constantly read a command's output in order to loop through it to determine something that is happening over our system. The command td <filename> interactively prints 'filename' as text is written to it and this is redirected to standard output. I have been... (8 Replies)
Discussion started by: fidodido
8 Replies
Login or Register to Ask a Question