General :: Command To Find / Replace In A Text File?

Feb 11, 2011

I have an SQL dump, file.sql that has many references to a particular domain, d1.com. I would like to run a command that can replace every occurrence of d1.com with d2.com. I've tried looking into sed before but the man pages are quite daunting.

View 14 Replies


ADVERTISEMENT

Ubuntu :: Bash Command To Find And Replace Text In File

Apr 3, 2010

I'm having problems with Tomboy. I have a few hundred note files and I need to go through all of them and replace all instances of "<link:broken>a</link:broken>" with "a". Is there a bash command I can use to do this?

View 2 Replies View Related

Ubuntu :: Command Line - Find And Replace Text Within Multiple Files?

Aug 28, 2010

I'm pretty sure this is doable from the command line, but my CLI skills have degraded a lot since my pre-Y2K admin days. The goal is to search all the files in the directory for a very long string of text and replace it with another string of text. The text being searched for is my Google Adsense code (which will be stripped from my website) and it will be replaced with a placeholder so I can easily tack something else in there in the future.

Seeing how I have that long snip of code on about 100 pages, automating the process would make life easier.
If I was searching for a single word, I can see ways to do this.
If I paste the code I'm searching for into a text file, is there a way to:
find (contents of oldstring.txt) and replace with (contents of newstring.txt)?

View 9 Replies View Related

General :: Find And Replace Text From Many Files In A Dir?

Jul 8, 2010

I have a many directories each with about 20 html files inside. All the files have .html ext. What I'm hoping is possible is from command line to find some text in each one and replace it with some other text.

Basically what I want to replace is;

/awstats/
with
awstats/

I can do this easily with dreamweaver or some other application but because I have 960 pages total to do I'm hoping to do it this way.

View 6 Replies View Related

Programming :: Command For Find/Replace In Text Files (inc. Files In Sub-folders)?

Oct 11, 2010

I found this command that works great finding and replacing a simple string to another in files located in that folder and all sub-folders.

Code: find . -name '*.php' | xargs perl -pi -e 's/OldText/NewText/g'

The problem I have is that I need to replace a more complex string, like this: Old string: /mnt/stor6-wc2-dfw1/627896/982574/ New string: /mnt/stor8-wc2-dfw1/369587/302589/ There I don't know how to do it... since the / is what separates the old from the new strings, and the strings that I want to replace have / in it. Also, I would like to know how to specify under what folder replace the files, for example, I want that it search/replaces all files under /var/www/mysite/htdocs folder.

View 1 Replies View Related

General :: Text Manipulation Find / Replace Variable Efficiency?

Aug 27, 2010

What I have works, but wondering what is the 'right' way to replace the digits with the letters given in this loop? somehow use a case or multiple sed? i thought of a multiple sed or a case but couldn't get it to work

Code:

# ...
bcv=$(echo $line | awk -F" " '{ print $1 }' | sed 's/1/q/g;s/2/w/g;s/3/e/g') # and so on

Code:

while read line
do
bcv=$(echo $line | awk -F" " '{ print $1 }')
if [ $bcv == "" ]

[code].....

View 12 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related

General :: Replace Text In One File With Text From Another File Using Sed?

Apr 28, 2010

How could I replace text in one file with text from another file using sed?

The text in each of the files would be surrounded by a starting and ending delimiter or a starting tag, say like /* */ so to easily find them.

View 8 Replies View Related

General :: Find And Replace Command For Whole Directory

Aug 17, 2011

Is there any command in Linux which will find a particular word in all the files in a given directory and the folders below and replace it with a new word?

View 4 Replies View Related

General :: Replace Nth Occurence Of String In Each Line Of A Text File?

May 20, 2010

I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:

sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt

View 2 Replies View Related

General :: Perl Script To Replace The Number From Text File?

Jun 21, 2010

on creating a new perl script which replace IP address from the text file. eg. If in a file, we found any word like 11.222.333.44 then it has to be replaced to XX.XXX.333.44

View 8 Replies View Related

General :: Command Line - Use Find To Find Text Files?

Jul 15, 2011

Is there a way to specify to find that I only want text files (and not binary files)? Grep has an option to exclude binary files, so I thought find probably has a similar feature, but I've been unable to find it.

View 2 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

Programming :: Exact Text Find And Replace?

Aug 13, 2010

I have a sysctl.conf that has the following in it:

kernel.exec-shield-randomize = 1
kernel.exec-shield = 1

When I grep kernel.exec-shield I get both line, hence I keep over writing the kernel.exec-shield-randomize in my script because it finds them both for my sed commend.

How can I get an exact match with either sed/awk/grep in shell so I can do a find and replace?

Example: sed 's/^kernel.exec-shield =.*/kernel.exec-shield = 1/g' /etc/sysctl.conf will replace BOTH lines

Example: grep "^kernel.exec-shield" find both line and I want it to find only the exact line.

View 3 Replies View Related

General :: Sed Command To Replace File Extension?

Dec 9, 2009

how to use a variable in a sed command, but I can't get the output into a variable.

FILE=readme.txt
now i want to remove the extension of filename
so file woud be:
FILE=readme

my script:

NFILE=`echo $FILE | sed 's/.txt//'`
mv ../out/$FILE ../out/$NFILE
FILE=$NFILE

now when i run my script. i get this unknown character extensions in my new file(NFILE).

View 14 Replies View Related

General :: Ubuntu - Replace A File In Jar With Command Line ?

Oct 18, 2010

I have a jar, and I need to replace a class in it, at this moment, I can only open it with "archive manager" and then drag and drop the new compiled class into the jar, but I think this is really boring, if I can do with with just a command ?

View 1 Replies View Related

General :: Find A Text In A File?

Jul 21, 2010

in directory so many files are there. if we want to find some text in all the files, what is command is to be used.

View 6 Replies View Related

General :: Convert An HTML Email Saved As A Text File To A PDF File From The Command Line?

Aug 23, 2011

I need to be able to convert HTML email messages saved as text files (.eml or .msg) to PDF documents, one PDF per email, retaining formatting and images.

Are there any Linux tools that will allow me to do this from the command line (so it can be scripted)?

View 1 Replies View Related

Ubuntu :: Vim Find/replace Command Using Wildcards?

Aug 1, 2010

I'm struggling with the Vim find/replace command using wildcards.

I have several, big html files with lots of instances of: <p stuffiwanttoremove>

I've been trying the Vim command: %s/<p *>/<p>/ge

but it doesn't seem to work.

Does anybody know what I'm doing wrong?

I realise there may be alternatives to this (eg a bash script)

View 2 Replies View Related

Ubuntu :: Replace All Tab Stops In A Text File With 4 Spaces?

May 18, 2011

How can I make vi and nano such that when I press the tab key, it automatically replaces the tab with 4 spaces?

View 5 Replies View Related

Ubuntu :: Script To Replace Characters In Text File?

Jun 30, 2011

I have an odd request, lets say I have a text file like this:

Quote:

Code:

__##___##___IIIIII
__##___##_____II__
__##___##_____II__
__#######_____II__
__##___##_____II__
__##___##_____II__
__##___##___IIIIII

I want a script that will replace all of the hash tabs with random characters.I found this command will generate a random character

Quote:

apg -a1 -n1 -m1 -x1 -d

how to script a search and replace using that random character upon each successive find until the end of file occurs.

View 9 Replies View Related

Server :: Using Find And Replace Command In Perl Script?

Jun 15, 2011

I have one perl sctipt which generate cfg file with ^M in all the EOL. I need to remove the ^M from the cfg file. How can i remove that from the perl script itself. I have tried the following unix command in perl script,

system("perl -pi -e 's/^M//g' *.cfg");

It doesn't work.

View 5 Replies View Related

Programming :: Find And Replace Using Passing A Parameter To Said Command?

Apr 9, 2010

I am trying following script can I do this or is there a way to do find and replace the replacing word is dynamic input by user

echo -n "Enter name:"
read RP_USER
sed 's/text1/$RP_USER/' /home/user/file1 > /home/user/file2

View 5 Replies View Related

General :: Find Text After String Search In File

Aug 2, 2011

I have a file called Regions.ini that looks like this:

Code:
[Granite]
RegionUUID = 54ab7cd2-0e70-49b7-8020-8dbeb84c08d0
Location = 9991,10007
InternalAddress = 0.0.0.0
InternalPort = 9001
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9

[Syenite]
RegionUUID = 8fc56fdd-0afd-4074-9432-0ae8f42b799f
Location = 9992,10007
InternalAddress = 0.0.0.0
InternalPort = 9000
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9
What I need to do is find out what the IP address is after "ExternalHostName ="

After that I will need to compare that IP to whatismyip and if it's different then replace it but that is easy to do with sed. I just can't figure this simple hurdle out.

View 12 Replies View Related

Programming :: Sed Script - Searching For Text Within File / Replace With Variable

Feb 25, 2011

Code:
#!/bin/bash
VARR=`cat /proc/asound/cards | grep HDMI | cut -c 1-2`
VARX="defaults.ctl.card $VARR"
VARY="defaults.pcm.card $VARR"
FILE1="alsa"
FILE2="alsa.new"
echo $VARX
echo $VARY
sed "s/defaults.ctl.card*/'$VARX'/g" $FILE1 > $FILE2

This is what I have right now. Well, I thought I knew sed, and apparently I don't... I tried writing this for someone else, and this has given me trouble, so since the user pretty much figured it out on his own, here it goes.
Say VARR=1, so VARX and VARY contain the above text, appended by 1.
What I am trying to do is replace the text "defaults.ctl.card 0" by VARX and "defaults.pcm.card 0" by VARY. The contents of FILE1 is the file being used to search for both text fields, and FILE2 is the output file. I tried using single quotes, double quotes, and a mixture of both, and no go whatsoever. So my question... What is the proper way of searching for text within a file and replacing with a variable?

View 5 Replies View Related

General :: Find A File In Directories Without Using Find Command?

Aug 3, 2010

am new to linux and trying to find a file in sub directories using find command as:find .-name *.jpg -type fBut I am unable to get the result as find command is not permitted by the server administrator.Is there any way to find files without using find command.

View 14 Replies View Related

General :: Replacing The Text In Same File Using SED Command?

Oct 11, 2010

I have a String like "A.words=Ajay,Anil" in file A.And it contains a lot of other information also. I wanted to replace "Ajay,Anil" with "Vijay,Vinay" with sed command with using existing file only(not using another file)

View 9 Replies View Related

Debian Programming :: Replace Certain Text In A File With Person Username Automatically?

Mar 16, 2014

Is there any way to use sed to replace certain text in a file with the persons username automatically? Right now i'm using
Code: Select allsed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g file.foo

I would like it to automatically inject the persons usrname in the replacement string. Is this possible? I've been looking on line at various sed tutorials and I cant quite find what i'm looking for. I also didn't really see anything in the forums search function.Essentially i'm trying to take this file URL...Android.rules and replace all instances of username with the persons actual username automatically.

Code: Select allsed -i.bak s/username/$USER/g 51_Android.rules

View 0 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 :: 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







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