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
ADVERTISEMENT
Jun 11, 2010
If I have the following links in HTML
Code:
<a href=lang.php?lang=cymraeg>Cymraeg</a>
<a href=lang.php?lang=english>English</a>
and lang.php has a link to page2.html, how do I pass on the value of the lang parameter from lang.php to page2.html? The value needed is the one passed in to lang.php.
View 3 Replies
View Related
May 6, 2011
I am very new to shell scripting.How does one pass a command-line parameter to a shell script?for the below program
#/bin/bash
mount -t cifs -o user=ramkannan,password=Linux123@ //10.200.1.125/ramkannan /MT
cd /MT/test
date=`/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"`
mysqldump -uroot -pram2@ employeedb > $date.sql
gzip $date.sql
I want to pass parameter for everything,i tried in google and did but iam getting error while passing parameter to all
#/bin/bash
mount -t cifs -o user=$1,password=$2 //10.200.1.125/ramkannan /MT
cd /MT/test
date=`/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"`
mysqldump -uroot -pram2@ employeedb > $date.sql
gzip $date.sql
i was getting error while passing parameter to all.
View 2 Replies
View Related
Jan 21, 2011
Say, i have an imaginary std library function, which I want to call.
Code:
void std_lib_func(ObjectType *param);
Now in my c++ program, I have a main() function, and I will like to call a customized function (which will in turn call the std lib function) from the main function, as below:
Code:
int main()
{
ObjectType *aobj;
customized_func(aobj);
}
[Code]...
I tried the below but get an error that the std lib function is expecting a ObjectType* param, not aobj. How should I work this out.
Code:
void customized_func(ObjectType aobj)
View 4 Replies
View Related
Apr 26, 2010
Ive read a few books and a lot of tutorials on C but can't find this topic explained in a deliberate way.I can find bits and pieces but nothing thorough.
View 9 Replies
View Related
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
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
Jul 9, 2010
I have a small board that has a static ram board attached to it. I have two different programs that each write to a byte of memory in the static ram board. I get a file descriptor to the device memory with the following code:
int phymemfd;
phymemfd=open("dev/mem, O_RDWR | O_SYNC);
This opens the physical memory for both reading and writing. Next I get a pointer to the beginning of my ram board.
volatile unsigned char *novram;
novram = (unsigned char *) mmap(0, getpagesize() * 31,
PROT_READ|PROT_WRITE, MAP_SHARED, phymemfd, 0x11AA0000);
I do this same code in two processes that are both running and this works fine. Now, if I take out the O_SYNC parameter, one of the programs gets into some sort of weird state.My understanding of the O_SYNC parameter is that it cause the process accessing the memory location to block, not allow another process to run, until the first process has finished writing to it.I can see that if my program doesn't block, I wouldn't really know what was in the memory location, but would I can't see how it would cause any other type of system problem.
View 1 Replies
View Related
Dec 17, 2009
I am calling another executable in my application (C programing) using "system" command
which is user interactive program. now i want to pass those args in system command only.
system(" executable ");
Executable will expect 1,2 or 3.
1 is to continue
2 for do changes in settings
3 exit from application
how to pass these in to system command
View 1 Replies
View Related
Jul 13, 2009
how to use QGLviewer. I want to give my program a file name as a command line argument. All of the sample programs I find have a main.cpp file like this:
Quote:
#include <QApplication>
#include "window.h"
int main(int argc, char *argv[])
[code]....
Then the Window class, which is derived from QGLViewer, does all the program's actual work. If I want access to argc and argv, for example, to open and read a file that's passed as an argument, what would handle that? Is there a built-in way to get the arg variables to the window class, or do I need to just write a loadfile function and pass them?
View 1 Replies
View Related
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
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
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
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
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
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
Mar 9, 2011
I am trying to make a simple alias for find command that acceps a variable.
alias myfind="find $@ -type d -exec chmod 777 -fv {} ;"
this alias tells me that "find:paths must precede expression"
View 6 Replies
View Related
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
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
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
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
Mar 11, 2011
I have a tab delimited file. I need to replace the 7th tab with a new line.
I tried the following command (but it does not work):
The above simply spits out the original file.
If I write the next command, it replaces the first tab in each line with a newline. How can I make it replace the 7th tab in each line?
View 4 Replies
View Related
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
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
Oct 30, 2010
I used a command Code:
grep -r err_sys ./
its output is
Code:
./tcpclitime.c:err_sys("socket error");
./tcpclitime.c:err_sys("connect error");
./tcpclitime.c:err_sys("write error");
./tcpclitime.c:err_sys("shutdown error");
./tcpclitime.c:err_sys("read error, n = %d", n);
[Code].....
Is it possible some how to replace all the occurrences of word err_sys by printf.
View 1 Replies
View Related
Dec 15, 2009
Here's the actual line of code, which exists in a bash script:
Code:
I want to replace instances like this:
Code:
with this:
Code:
Using this:
Code:
Which works great when there's only ONE of the pattern on the line. But in a case like the "actual line" I posted first, where there are two patterns, separated by a slash, only ONE gets replaced
Watch:
Code:
Why? There must be (among many other things) something I'm not knowing about sed, that's causing this.
-- I'm currently using the ~ (tilde) as the separator in the sed command. It doesn't matter, I've used / ~ and % with no difference.
-- As a test, I tried putting a different character(s) in the middle of the original pattern instead of the / but that made no difference.
-- I've come up with various similar but slightly different regexs that will do this replacement, but they all have had this same result.
-- I tried the sed single-quoted, double-quoted, and unquoted; the latter fails to execute, and the formers both work as described here: wrong.
View 7 Replies
View Related
Nov 13, 2010
I want to use the output of a previous command as a parameter to another command. For example: to know where "nice" is stored i typed: which nice output: /usr/bin/nice now the second command i typed is: ls -l /usr/bin/nice Is there a way to have a single command like: ls -l which nice ?
View 4 Replies
View Related
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
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
May 28, 2010
I am unable to find any ldap.conf parameter or pam.d/system-auth setting from where i can restrict the LDAP users having uidNumber less than a particular number, say 500 to login into the system.I am using OpenLDAP server and tried pam_max_uid 500 in ldap.conf but it didn't work.
View 2 Replies
View Related