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


ADVERTISEMENT

Programming :: Replace Character With Hex Value Choosing From Shell Cmd Line?

Jun 9, 2011

I am bouncing a file across platforms (windows->solaris->mainframe), and the file is starting out with a "special" character (the registered trademark "circle R") in some of the records. This character is not in the EBCDIC character set on the MF, so it is unrecognizable. The MF developer I am working with asked if it is possible to replace the character with a specific hex value (AF) before it gets to the MF.

I was putzing around with sed, tr, etc. on the ksh command line, hoping to find an easy way to get one of them to substitute hex instead of ASCII. I have found that the usual shell utilities recognize the trademark character, so homing in on what to replace is solved. But I cannot get anything to actually substitute in the hex sequence I want. E.g. I was thinking something like...

>cat special_file | sed 's/R/AF/g'

But my version of sed does not seem to have hex "editing" capability.

View 5 Replies View Related

Programming :: Shell Script Replace A Line From A File?

Mar 4, 2010

I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning

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

General :: "find And Replace" In Shell (includes The / Character)?

Feb 27, 2011

I would like to know what shell command I could use for finding a phrase (which is a URL) in many files, with a different phrase. I have tried the "sed" command, but it does not like the forward slash.

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

Programming :: Shell Script To Find Usb Device Name?

May 19, 2011

I have a usb to serial converter which i plug in to Ubuntu Natty.I see that on every reboot this seems to come up as a different device name, say ttyUSB0, ttyUSB3 etc.I want to write a simple shell script to get the name of the device in a shellscript.

View 1 Replies View Related

Programming :: Find / Write A Shell Script That Will Go Through A File Organized?

Jul 3, 2009

I am trying to find / write a shell script that will go through a file organized like this (but with thousands of lines)...

93,5.00,"contig00002",169,83,"jgi|Brafl1|100379|fgenesh2_pg.scaffold_359000019"
579,1.00,"contig00003",3,380,"jgi|Brafl1|114745|estExt_fgenesh2_pm.C_1200006"
450,5.00,"contig00007",2,352,"jgi|Brafl1|274326|estExt_GenewiseH_1.C_8420008"

...and check the region of each line between the second and third pipes (the 6-digit numbers) against the values in the first column of a separate text file in CSV format like this...

274326,"Wnt family of developmental regulators"
114745,"FOG: Hormone receptors"
100379,"Transcription factor tinman/NKX2-3, contains HOX domain"

...and when they match, replace the value to the right of the third pipe (e.g., fgenesh2_pg.sca...) with the value in the second column in the CSV file associated with that number.

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

Ubuntu :: Replace Desktop With A GUI Shell?

Aug 13, 2010

I would like to configure my Ubuntu as to start Gnome without a Desktop; instead, I would like to have a graphical shell taking the whole screen, but keeping all the other functionalities of the GUI.

It doesn't really have to be Gnome - I would gladly take any GUI with the above-mentioned description that would open Firefox, Amaya and Calibre.

I am trying to save some memory with a feeble Acer Aspire One that is solely used for browsing the web (Firefox), editing webpages (Amaya), and creating .mobi files.

how to replace the Desktop with a shell or taking a different approach?

P.S.: I looked at the Ubuntu Netbook Remix and the soon-to-be-released Gnome Shell, but they are not what I am looking for!

View 5 Replies View Related

Programming :: Find Logarithm To Base 10 Instead Of Base 2 On Shell Script?

Apr 20, 2010

can we find logarithm to base 10 instead of base 2 on shell script??i can do it with bc..like 'l(1000)/l(10)' | bc -l

View 1 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 :: Shell Scripting / Create A Shell Script Similar To Ls?

Jun 5, 2011

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.

Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....

View 10 Replies View Related

General :: Find Or Replace Without Using Sed?

Dec 27, 2010

I am working on writing a script for find and replace a string using sed.But know I want to write without using sed.

View 9 Replies View Related

Programming :: Bash-shell-like Less Functionality In The Python Shell?

Jun 25, 2010

Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?

Example:

Code:

>>> import subprocess
>>> help(subprocess)
...
[pages of stuff to read]
...

I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.

View 4 Replies View Related

General :: Find And Replace String?

Jul 26, 2011

I need to find this "TYPE=MyISAM;" and replace with "ENGINE=MyISAM;" in all .sql files in a directory. How can I do this with sed?

View 2 Replies View Related

General :: Sed Find And Replace With Wildcard?

Aug 5, 2011

I would like help with modifying the following content:

toolbox/perl/man/man3/ExtUtils::Command.3::Command.3 differ
toolbox/perl/man/man3/ExtUtils::Command::MM.3::Command::MM.3 differ
I would like the content to be changed to:
toolbox/perl/man/man3/ExtUtils::Command.3
toolbox/perl/man/man3/ExtUtils::Command::MM.3

I was not sure how to tell sed what to look for? I tried the following but it did not work. sed -i 's/::* differ//g' mandiff.log

View 3 Replies View Related

Software :: How To Find And Replace On All Backslashes

Feb 8, 2010

I'm in the middle of a data migration project and I have a text file where the data in one of the fields contains a "" at the end of each line. I know how to do a find and replace on ALL backslashes using something like this:
Code:
:%s/\//g
The above example would replace all backslashes with nothing, effectively "removing" them. Does anyone know how I can apply a similar function that only removes the backslashes that exist at the end of a line?

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

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 :: Find And Replace With Sed At Beginning Of A Word

Nov 15, 2010

I want to write a small script to rename a bunch of files. Their name is of the form 'long number'|'name'|'extension', for example:

52354Football_part2.flv
2353452Nice_weather_4_ducks.flv

I would like to rename these to:

Football_part2.flv
Nice_weather_4_ducks.flv

If in my script I use something like

Code:
sed s/[0-9]//g
on each file, I will get
Football_part.flv, instead of Football_part2.flv,
and
Nice_weather__ducks.flv, instead of Nice_weather_4_ducks.flv.

how to instruct sed to only remove numbers that are in the beginning of the name in a simple way?

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

Server :: Find And Replace In Multiple Files In Ssh?

Jul 3, 2010

Find and replace in multiple files in ssh?

View 1 Replies View Related







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