Programming :: Multi File Recursive Folder Search And Replace?

Aug 3, 2010

I'm wanting to mod some PHP files across a hierarchy and thought I'd drive it with find + grep + xargs

I built up a command line which I was confident would do the job, but now can't save the results.

First I tried this:

Code:
find . -name *.php | xargs grep serialize | cut -d: -f1| sort -u | xargs sed -i s/serialize/serialise/g
but that didn't work:
Code:
sed: illegal option -- i
so I thought I'd try using
Code:

[Code].....

View 10 Replies


ADVERTISEMENT

Programming :: Recursive Search In A Tar.bz2 File?

Jul 14, 2011

I am looking for a one liner to search for a string in file(s) which are in a tar ball (.tar.bz2 in my case)

Code:
-bash-3.2$ tar -tjf /var/log/ABC/07142011-1412.tar.bz2
var/log/ABC/07142011-1412/
var/log/ABC/07142011-1412/live_hosts.txt
var/log/ABC/07142011-1412/all_hosts.txt
var/log/ABC/07142011-1412/LOGS.txt

How can I recursively look inside all the txt files in this tar file ?

View 10 Replies View Related

Programming :: Bash - Recursive Find - Create Parent Folder - Moving File

Dec 5, 2010

I'm starting bash shell script and I'm looping without any solution.

I'm trying to find some files under a folder hierarchy and in case of errors moving these files to a destination folder under the same hierarchy recreating this hierarchy if not exists.

Finding all ._* files under /src and moving them to /dest recreating folder1 or the others which contains ._* files but without moving files which does not correspond to the pattern.

Code:

I tried find command and I'am getting all needed files

Code:

But I don't know how to use the output to get the parent folder of files which are found to

1- create folder with mkdir -p /dest/folder1 or /dest/folder1/folder4

2- move found files from /src/... to /dest/... with rm command

I'm working on a find command as this trying to do all in the same line but ... little lost

Code:

View 8 Replies View Related

Programming :: Search And Replace In A Binary File?

Aug 11, 2010

i need to change a binary file, let's say to find and replace username:

find string: "/home/name/bla-bla-bla/ "
new string: "/home/anewname/bla-bla-bla/ "

i can do it, for example, in emacs (hexl-mode), but interesting in writing a script instead. it will be much more better for me if i could do it automatically. is there an analog of: sed 's/string1/string2/g' ? P.S. the best way is to recompile the binary files i have, but there are no sources available.

View 5 Replies View Related

Programming :: Sed One-liner: Search Text In File And Replace It - If Not Present Insert It?

Oct 16, 2010

As indicated in the subject, I want to search a text. If the text is present I want to replace it. But if the text is not present, I want to insert it after first line and before last line.

Searched text is:CleanCache "*";

Where * can be anything.

Example: CleanCache "false"; -> CleanCache "true";

If CleanCache "false"; is not present, only insert CleanCache "true"; after first line and before last line.

View 8 Replies View Related

Programming :: Write A Utility Which Will Scan In A Text File And Search And Replace Strings?

Jul 16, 2010

Something very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search and replace strings. We also want to keep track of how many strings we've replaced.

I know that my command would look like this: <utility name> <filename> <stringToSearchFor> <stringToReplaceWith>
Code: #!/bin/bash

[code]....

View 2 Replies View Related

Programming :: Find Command To Search For All The File In The Particular Folder?

Aug 2, 2011

how to use find command to search for all the file in the particular folder?my script as below

find . -name "*" > $BASE/file
if [ `more file | wc -l` -gt 0 ]; then
echo "dp"
fi

output of my results will always include a . (dot)which I dunwan it include the dot.

View 11 Replies View Related

Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?

Feb 24, 2010

I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?

View 1 Replies View Related

Programming :: Test Permissions On All Files / Folders Into A Folder Recursive?

May 16, 2010

Way to test permissions on all files/folders into a folder recursive, then if those are not user:user then do :

Code:
chown user:user thatconcernedfile

The problem with that

Code:
chown user:user -R /folder

is that it is doing changes on file permissions whihch are already ok. If you wanna maintain a specific permission on a folder this is really not good this :

Code:
while [ 1 ] ; do
chown user:user -R /folder
# /folder contains 6.0 Tb
sleep 2s
done

View 1 Replies View Related

Programming :: Multi-line Find - Replace With GnuWin32 Sed?

Apr 26, 2009

I would like to have a script that will do a search in an XML file for a specific block of XML code and replace it with a different block of XML code using the Windows build of GNU Sed 4.1.5.

Here's the text I want to find:

Code:

And here's what I want to replace it with:

Code:

There is however a lot of stuff in there that would mess up sed, and the one example from the sed FAQ (from the Sourceforge site) that looked promising and easy enough to figure out (4.23.3. Try to use a block of "literal strings") fails with this error message: sed: file blockrep.sed line 18: unterminated `s' command

Anyone got any ideas, or even an alternate program that can do this? (Preferably one that I can automate.)

View 4 Replies View Related

Programming :: Using Sed To Search And Replace Backwards?

Oct 25, 2010

I'm trying to use sed to search and replace backwards. The problem is that I have a shell script that is required to put commas into big numbers. For example

9999999 as 9,999,999

I've tried a few things, but none seem to work:

Code:

$ echo 9999999 | sed -e 's/([0-9]{3})/,1/g'
,999,9999
$ echo 9999999 | sed -e 's/([0-9]{3})$/1,/g' -e 's/([0-9]{3})/1,/g'
999,999,9,
$ echo 9999999 | sed -e 's/([0-9]{3})$/1,/g' -e 's/([0-9]{3})/,1/g'

[ode]....

It would be much easier if I could search backwards! For example Bash parameter substitution style:

Code:
$ echo 9999999 | sed -e 's%([0-9]{3})%,1%g'

View 14 Replies View Related

Programming :: Awk Multiple Line Search And Replace?

May 1, 2011

I am trying to search and replace a multi line pattern in a php file using awk.The pattern starts with

<div id="navbar">
and ends with
</div>

[code]...

View 3 Replies View Related

Programming :: Bash Search Line And Replace Hex To Binary?

Jul 7, 2011

I need a command to search a string in a file and then to convert the next string in the same line from hexadecimal to binary. I was able to put everything in capitals. The original file can be as such:

E 2
C 1 794
T ffff
E 2
C 1 787

It is not always FFFF! I am trying to do this in a file at once, not reading line by line (using while).

View 5 Replies View Related

General :: Shell Script To Search One File For Contents Of Another And Replace Text?

Feb 3, 2011

Suppose I have a pair of files containing lists. The first file is called contigs.txt and it contains a list that looks like this:

Code:
Contig822
Contig826

[code]...

View 5 Replies View Related

General :: Recursive String-search In Files?

Oct 28, 2009

find out a command to search among all *.dat files in a certain path (including subdirectories) looking for the following text in them:

Code:

--------------------------------------------------------------------------------
Elements with small area
Element Adjusted nodes
--------- --------------
16294 NO
17889 NO

and getting the list of elements with small area printed in a file "ErrorEl.txt". The output should have this form:

"/path/01/A.dat
bad-el#01
bad-el#02

[code]....

I know already how to find out the dat files containg a certain string

Code:

c=/path/
grep -R --include="*.dat" "Elements with small area" $c | cut -d: -f1>> ErrorEl.txt

but I don't know then how to get the element numbers(16294 and 17889 in the example above)

View 11 Replies View Related

General :: Recursive Search For Files That Hold Some Specific Text?

Jan 18, 2011

How do I recursively generate a text file which has a list of all files on my server which contain a specific string anywhere in the files?

I know the following command can be used to replace a string recursively

find /var/www -type f -print0 | xargs -0 sed -i 's/old string/new string/g'

I do not want to replace the string, I just want a list of all files which contain the string.

View 4 Replies View Related

Software :: Grep Recursive Search Directory Depth Option ?

Feb 28, 2011

I know grep can search recursively (ie through all subdirectories to the bottom of the directory tree), but is it possible to ask grep to only search say, 3 levels down? That means the current directory, any directories in the current directory, and within any directories within those?

View 1 Replies View Related

Ubuntu :: File Search On Home Folder?

Jul 11, 2010

I can't search file in another folder other than the home folder. Like when I try to search in my mounted NTFS drive, it only shows and only searches my home folder, not the current open folder in mounted drive. I also have installed "Beagle Search" to index my data and reduce time searching,

View 2 Replies View Related

Programming :: Perl Find File And Then Replace String In File

Jul 28, 2009

I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far

Code:

This finds the files but now i need to figure out how to do s/bob/fred/g on those files.

View 5 Replies View Related

Programming :: Using File As Replace In Sed

Mar 1, 2011

I have a file, "outfile" what I wish to insert into a file called template where it finds "OVERRIDES". I am getting an error.

Code:

However I can do something like this and it works fine

Code:

I am guessing its because of the file size or multiple lines.

A sample of the outfile text is below

Code:

View 9 Replies View Related

Programming :: How To Search For A File?

Feb 3, 2010

How to search for a file? I am looking for a file in a directory /shared/domain...This also contains many sub directories..I need a script which will let me know the location of my log file myapps.log.what is the script ?Can it be made in one line ...because I just want to run ...don't want to save the script.

View 14 Replies View Related

Programming :: Replace A String Within A File ?

Feb 28, 2009

I've found some scripts that replaces a string in a file but it's not quite working for me.

And I'm trying to replace a tag in an xml file that looks like this

So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml

And I get a error output

Search pattern not terminated at -e line 1.

Found the script from this blog [url]

View 7 Replies View Related

Programming :: Replace Part Of A File With Another?

Jan 8, 2010

There are a few things I was wondering about (using tools available in bash):How to insert a file at at the specified location of another.How to copy a portion of a file between two lines matching a regex to another file (and/or making sed only work between two lines matching a regex)How would you do this?

View 2 Replies View Related

Programming :: Replace Whitespaces With Dots "." On All Files In Folder?

Nov 9, 2010

I have a lot of .avi,.mkv,.srt files with empty spaces that needs to be filled out with a dot "."

Example:

With space = "my movie file here.avi"
Replaced with dots = "my.movie.file.here.avi"

View 7 Replies View Related

Programming :: Replace 2nd Occurrence Of A String In A File - Sed Or Awk?

Apr 5, 2010

I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.

For example, here is a file:

Code:
John
Betty
Jack
Ron
Jack
Paul

So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.

View 10 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Search A Bunch Of Files In A Specific Folder For A Specific Number?

Jul 24, 2010

I need to search a bunch of files in a specific folder for a specific number and add all the numbers together to a total sum. I use Rsync everyday, everytime I run rsync i get a logfile (rsync output) witch contains the textstring "Total bytes sent: xxxxxx".

The "xxxxx" can vary in lenght. I need to extract the "xxxxxx" from each file and add the numbers together to a total size over a week or a month. Is this possible? And I wish to only use bash. One way of doing stuff at a time my friends .

View 5 Replies View Related

Programming :: C++ Character Search In Text File?

Jun 23, 2011

Im trying to read a file in c++ and search for particular character for example if this is a list that I have:

Alice
Bob
David

[code]....

if the input is D, it should give David, if its B, gives bob. so in this case, meaning it reads the first character of every line. but if possible I want to make this dynamic so the user can specify which character position he is looking for, so in case he is looking for R as character index 3 in all lines, it should give Charlie. but the problem is, it does now recognize , besides, I do not know how to specify the character position in each line.

here is my code

Code:

#include <iostream>
#include <fstream>
#include <cstring>

[code]....

View 1 Replies View Related

Programming :: Search For Ip Address In File And Remove It

Sep 22, 2009

I have a lot of files in the server with name like checkfile.jsp and in the file has two or three lines with an ip address xxx.xxx.xxx in it. I wish to know if there any command to grep for the i p address and remove itin file but keep the " ", eg "xxx.xxx.xxx"

View 9 Replies View Related

Programming :: Replace Spaces With Underscores In File Names?

Jan 11, 2011

I often get files with many spaces as part of their names. I would like to automatically replace these spaces with underscores, but otherwise not change the file name. Is there a way to do this task with just the bash shell?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved