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


ADVERTISEMENT

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

Programming :: Using Grep To Find EXACT MATCH?

Nov 11, 2010

I'm trying to find exact matches of some users in the /etc/passwd file using "grep -w", but it doesn't always work. For example, I have the following users:[URl].. So, let's say, I want to search for the user "stewart" (which doesn't exist)

[Code]...

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

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

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

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

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 :: Using .sh Script To Replace Text?

Feb 24, 2011

i'm trying to script a lil piece to execute in terminal so when i type something like:

scriptname textfile

the script searches the text file, replaces charecters of my choosing with charecters of my choosing

"sed" im told is the way to go, and i got summat like this going

Code:

#!/bin.sh
bash -c "sed -i.backup -e /s/char/newchar/"

(if need be, i think i can just add another line of "-e /s/char/newchar/" if i need to target more charecters or words as needed.) the issue with the above code. . . how do i get it to target whatever text file follows the command? without having to manually designate sed to it each time? e.g. in commanding:

scriptname textfile

how do i get the script to target textfile^^^?

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

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

Programming :: Find And Replace Multiple Instances?

Aug 13, 2010

I have a file with the following in it:

:0 local /usr/X11R6/bin/X -nobanner
:1 local /usr/X11R6/bin/X

I need to add "-nolisten tcp" to both of these lines and cannot figure out how to do it. I can get it to do the first one, but not the 2nd and so on. How do I search the file and loop though it to change them all?

View 14 Replies View Related

Programming :: Find And Replace With A Shell Script?

Mar 10, 2009

What is best way to replace the 1 and the 3 below with a 0 using a shell script? It is in a text file with lots of lines and similar lines:

lots of text
...
useHeloBlacklist:=1
DoIPinHelo:=3
...
lots of text

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

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 :: Python - Find And Replace While Typing In Raw Input

Apr 30, 2010

I'm writing a program in Python that presents a place for the user to input one-line of text (using raw_input). I need, however, as the user types, for certain words to be replaced, even before the user hits enter.

I try to make an animation so you can see what I mean, here the word "pig" gets replaced with "sheep":
>I|
>I |
>I l|
>I li|
>I lik|
>I like|
>I like |
>I like t|
>I like to|
>I like to |
>I like to e|
>I like to ea|
>I like to eat|
>I like to eat |
>I like to eat p|
>I like to eat pi|
>I like to eat pig|
>I like to eat sheep|

Note, the user never typed "sheep", the program replaced "pig" with "sheep" as soon as they finished typing the word "pig". The user did not use "Enter". Is this at all possible in Python?

View 4 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 :: Search For Exact Repetitions In Text File

Nov 23, 2010

I've got a big text file in which I know have probably made some typos (LaTeX). Sometimes I rewrite sentences several times and then end up with double pieces like "the the" or "is is" without noticing it. Most spell checkers that I can use in LaTeX are very basic so they do not notice these grammar errors. Is there a way that I can search for these repetitions by hand using sed or awk or something along these lines? Is there an app for that?

View 3 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 :: Find Files With Missing Text?

Oct 19, 2010

Need to make sure a security line is added in to every webpage on a site, trying to find out how to list only the filenames of the pages that are missing the text. awk or grep? o what I want is to list all files NOT containing the word 'securemasthead'

View 2 Replies View Related

CentOS 5 :: How To Find Out Exact Version

Jan 27, 2010

Assume I am sitting in front of a runnning CentOS.How can I find out the EXACT version of this installation?I am not (only) talking about the major release (e.g. 5) but the sub release (5.1 or 5.2 or 5.3 or...)The about box shows something about Gnome but not the details for the CentOS.

View 1 Replies View Related

Programming :: Find String In Text File And Add Something To That Line

May 26, 2011

I want to know how can I add something to a specific line.. the output would be something like:
abc
def 123
ghi

Search for string "def" and add something to that line.

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

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

General :: Find Out Exact Kernel Parameters When Corrupt Boot Loader?

Feb 8, 2010

How do i find out the exact kernel parameters (from the grub config file) when the boot loader is corrupt. Seems like a catch 22 that I need the exact boot parameters when I cant get to a prompt to read the grub.conf file to being with.

View 2 Replies View Related







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