01-29-2009
how to do search and replace on text files in directory
I was google searching and found
Perl as a command line utility tool
This almost solves my problem:
find . | xargs perl -p -i.old -e 's/oldstring/newstring/g'
I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I don't want to make a copy of them.
How would I filter it thru grep first so I only perform search and replace on those files that have something to replace?
Also: how do I avoid running perl on directories. I looked at the "man find" on cygwin (sorry, I'm using cygwin on windows, please don't shoot me).
I tried
/usr/bin/find . -empty -prune
but this did not omit the directory files. Is this a bug in cygwin? I don't want to run perl on my directory files!
Thanks,
Siegfried
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello
I need to search for a mult-line text in a file exfile1 and replace that text with another text. The text to search for is in exfile2 and the replacement text is in exfile3.
I work with kornshell under AIX and need to do this with a lot of files. (the file type is postscript and they need... (10 Replies)
Discussion started by: marz
10 Replies
2. Shell Programming and Scripting
Hello all
I need to search and replace in multiple files that are in directory hierarchy
Im using the :
find . -name "*.dsp" -print | xargs grep -n -o Test.lib" , I like to be able to replace every instance of Test.lib
with empty space .
how can I write one liner that does this ? (3 Replies)
Discussion started by: umen
3 Replies
3. Shell Programming and Scripting
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
4. UNIX for Dummies Questions & Answers
I have a text file with following content (3 lines)
filename : output.txt
first line:12/12/2008
second line:12/12/2008
third line:Y
I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before.
I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
5. UNIX for Dummies Questions & Answers
I need to search for a particular string. This string might be present in many files. The directory in which I am present has more than one subdirectories. Hence, the search should check in all the subdirectories and all the corresponding files and give a list of files which have the particular... (5 Replies)
Discussion started by: pakspan
5 Replies
6. Shell Programming and Scripting
Hello,
I am trying to search and replace but I don't know how to do it. My simple knowlegde in search and replace using sed is not helping me at all.
File:
its a cause value #22: dfg ggg
Cause value #1: aasfa fasdf
asfa value #22: affg gggg
Basically i want to replace the... (6 Replies)
Discussion started by: balan1983a
6 Replies
7. Shell Programming and Scripting
Hello,
I am very new to Linux and am trying to find a way for following problem.
I have a number of files in a folder as Export000.dat, Export001.dat ..and so on.
Each file has a string field 'Absolute velocity'. I want it to be replaced by 'Pixel shift' in all the files. I tried something like... (4 Replies)
Discussion started by: chirag.joshi
4 Replies
8. UNIX for Advanced & Expert Users
HI
I have property files having content
QA_server_name=10.232.54.7
QA_port_number=18000
DEV_server_name=10.235.60.73
DEV_port_number=18000
and a .jason file having content like this
{
"server":"localhost"
"port":"17000"
------
}
I will get the parameter... (1 Reply)
Discussion started by: mdtausifsh
1 Replies
9. Shell Programming and Scripting
Hello All,
Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s):
WARNING: </d1/test/program1> did not find item1
WARNING: </d1/test/program1> item1 does not exist
WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies
10. Shell Programming and Scripting
What is the best way (bash/awk/sed?) to read in two text files and do a keyword search/replace?
file1.txt:
San Francisco
Los Angeles
Seattle
Dallas
file2.txt:
I love Los Angeles.
Coming to Dallas was the right choice.
San Francisco is fun.
Go to Seattle in the summer.
... (3 Replies)
Discussion started by: pxalpine
3 Replies
LEARN ABOUT DEBIAN
prima::editdialog
Prima::EditDialog(3) User Contributed Perl Documentation Prima::EditDialog(3)
NAME
Prima::FindDialog, Prima::ReplaceDialog - standard interface dialogs to find and replace options selection.
SYNOPSIS
use Prima::StdDlg;
my $dlg = Prima::FindDialog-> create( findStyle => 0);
my $res = $dlg-> execute;
if ( $res == mb::Ok) {
print $dlg-> findText, " is to be found
";
} elsif ( $res == mb::ChangeAll) {
print "all occurences of ", $dlg-> findText,
" is to be replaced by ", $dlg-> replaceText;
}
The "mb::ChangeAll" constant, one of possible results of "execute" method, is defined in Prima::StdDlg module. Therefore it is recommended
to include this module instead.
DESCRIPTION
The module provides two classes - Prima::FindDialog and Prima::ReplaceDialog; Prima::ReplaceDialog is exactly same as Prima::FindDialog
except that its default findStyle property value is set to 0. One can use a dialog-caching technique, arbitrating between findStyle value 0
and 1, and use only one instance of Prima::FindDialog.
The module does not provide the actual search algorithm; this must be implemented by the programmer. The toolkit currently include some
facilitation to the problem - the part of algorithm for "Prima::Edit" class is found in "find" in Prima::Edit, and the another part - in
examples/editor.pl example program. Prima::HelpWindow also uses the module, and realizes its own searching algorithm.
API
Properties
All the properties select the user-assigned values, except findStyle.
findText STRING
Selects the text string to be found.
Default value: ''
findStyle BOOLEAN
If 1, the dialog provides only 'find text' interface. If 0, the dialog provides also 'replace text' interface.
Default value: 1 for "Prima::FindDialog", 0 for "Prima::ReplaceDialog".
options INTEGER
Combination of "fdo::" constants. For the detailed description see "find" in Prima::Edit.
fdo::MatchCase
fdo::WordsOnly
fdo::RegularExpression
fdo::BackwardSearch
fdo::ReplacePrompt
Default value: 0
replaceText STRING
Selects the text string that is to replace the found text.
Default value: ''
scope
One of "fds::" constants. Represents the scope of the search: it can be started from the cursor position, of from the top or of the
bottom of the text.
fds::Cursor
fds::Top
fds::Bottom
Default value: "fds::Cursor"
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.
SEE ALSO
Prima, Prima::Window, Prima::StdDlg, Prima::Edit, Prima::HelpWindow, examples/editor.pl
perl v5.14.2 2009-02-24 Prima::EditDialog(3)