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


ADVERTISEMENT

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

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

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

Programming :: Find String In Text File (bash Script)

Apr 17, 2011

write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.

For example. File: PHP Code: PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22) 

[Code].....

View 1 Replies View Related

Ubuntu :: Bash Script To Delete/replace A Specific String Of Text?

Jun 17, 2010

What i want to do is pretty simple.I want to uncomment every line that begins with "deb" (except for deb cdrom) in /etc/apt/sources.list.I know how to do this through system > administration > software sources.I know I can gksu gedit /etc/apt/sources.list.I'd rather not do it that way.I'd rather have a script do it. It's less work, less typing, less clicking, and would work the same on every ubuntu version.

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

Programming :: Find And Replace Script In Bash?

Sep 28, 2010

Im looking for assistance to create a script to find and replace files.Probably best if I give you the background Our server uses a specific application which stores user data, each user data account (a folder on the server) has a file called 'Profile.xml' this file gets updated and replaced about every 30 mins similar to the fashion logrotate works i.e. Profile.xml.1 Profile.xml.2 -> .10

What we experience is that if the application crashes unexpectedly while it is doing its user profile refresh task we end up with sometimes a few hundred Profile.xml files which end up 0kb(should be around 4kb) , and our server see's these as corrupted profiles and will not see them. Our fix is to go back thru and rename the Profile.xml.1 to be Profile.xml (or sometimes up to Profile.xml.5 to Profile.xml) We want a script we can manually run to automate this process The server tree is

/mnt/array1/username/db/Profile.xml
/mnt/array2/username/db/Profile.xml
etc
etc

What we have so far is a script which finds the affected files

find /mnt/ -maxdepth 4 -name Profile.xml -size -1k

This will display a list of affected profiles, and we can append it to a text file with >>output.txt on the end.

if 'pattern' in 'location' equals '0kb' then 'cp' Profile.xml.1 Profile.xml

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

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 :: Bash: Replace All Occurrences Of A Word In The Last Command

Mar 9, 2011

Almost by mistake, I figured out you could do something like:

$ cp foo.data bar1.data
$ ^bar1^bar2

And that runs the same command with bar2.data instead of bar1.data. Now, how about if I have multiple occurrences of the target word? For example:

$ cp foo.data bar.data
$ ^data^index

It only replaces the first data extension. How do I get it to replace both?

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

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

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

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

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

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

Programming :: Text File Replace Occurrences Of Three Character String ZZZ With Quotation Mark

Mar 30, 2010

I want to use SED to do the following: In a text file replace any occurrences of the three character string ZZZ with a quotation mark "and. replace all occurrences of a comma with a semi-colon. It is the S/ / / command which is stumping me on the first issue...inparticular how to get the replace string to be quote.

View 9 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 :: Perl: Find Variable Text Between Keywords And Replace W/ "term_<variable_text>_term"?

Jul 12, 2010

I am trying to write a Perl script that can open a file, find text that appears between two identifying strings (for now, "start" and "end"), then modify that text by enclosing it between "term_" and "_term" . Since the identified strings vary, the replacement string becomes "term_$1_term". From looking at other threads in this forum I've been able to get as far as spitting out the modified terms using the following code:

open FILE, "start2.txt" || die ("Could not open file <br> $!");
$text = <FILE>;
while ($text=~ s/start (.*?) end//) {

[code]....

The problem is how to get "term_$1_term" into the file in the same while loop, which I'm guessing would be some of variant of "$text=~ s/$1/$term/;" (which doesn't work as it stands).

View 6 Replies View Related







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