Programming :: Replace The Default Path In A File(which Is A Script)?

Jul 19, 2010

I am trying to replace the default path in a file(which is a script)with the new path which I have get when the bash script runsThe code is

SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
sed -i "s/$HomeDir/$SCRIPTPATH/g" <filename>

[code]....

View 4 Replies


ADVERTISEMENT

General :: Replace A String In A File Using A Script With Path Containig /

Feb 26, 2010

I need to replace a string in a file(startup.sh) using a script(parser.sh). After running parser.sh startup.sh should be filled with nfs path like /home/vimal etc but im getting error since path contains /. how to remove this.

View 3 Replies View Related

Slackware :: Default PATH - Python: Can't Open File 'SABnzbd.py': [Errno 2] No Such File Or Directory

Nov 24, 2010

I have just installed SABnzb application in my home folder. The executable file is SABnzb.py When I run the command in the Konsole # python SABnzb.py I have this Quote: python: can't open file 'SABnzbd.py': [Errno 2] No such file or directory

View 5 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 :: Using File As Replace In Sed

Mar 1, 2011

I have a file, "outfile" what I wish to insert into a file called template where it finds "OVERRIDES". I am getting an error.

Code:

However I can do something like this and it works fine

Code:

I am guessing its because of the file size or multiple lines.

A sample of the outfile text is below

Code:

View 9 Replies View Related

Programming :: Replace A String Within A File ?

Feb 28, 2009

I've found some scripts that replaces a string in a file but it's not quite working for me.

And I'm trying to replace a tag in an xml file that looks like this

So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml

And I get a error output

Search pattern not terminated at -e line 1.

Found the script from this blog [url]

View 7 Replies View Related

Programming :: Replace Part Of A File With Another?

Jan 8, 2010

There are a few things I was wondering about (using tools available in bash):How to insert a file at at the specified location of another.How to copy a portion of a file between two lines matching a regex to another file (and/or making sed only work between two lines matching a regex)How would you do this?

View 2 Replies View Related

Programming :: Specifying A File Path In IDL?

Jul 19, 2010

I've been dabbling in IDL lately, and it seems useful enough, but occasionally I come across a problem like this: I'm trying to call an IDL procedure from within an IDL script which is called from a .csh script. (Don't ask, trust me, you don't want to know.) The IDL procedure may or may not be in the same directory as the .csh, so I'm calling it by it's full path: /home/ic/rad_sim However, all IDL will do is give me a syntax error and tell me ic is an undefined variable. Putting ic in double quotes makes the undefined variable error go away, but it still reports a syntax error.

View 13 Replies View Related

Programming :: Search And Replace In A Binary File?

Aug 11, 2010

i need to change a binary file, let's say to find and replace username:

find string: "/home/name/bla-bla-bla/ "
new string: "/home/anewname/bla-bla-bla/ "

i can do it, for example, in emacs (hexl-mode), but interesting in writing a script instead. it will be much more better for me if i could do it automatically. is there an analog of: sed 's/string1/string2/g' ? P.S. the best way is to recompile the binary files i have, but there are no sources available.

View 5 Replies View Related

Programming :: Replace 2nd Occurrence Of A String In A File - Sed Or Awk?

Apr 5, 2010

I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.

For example, here is a file:

Code:
John
Betty
Jack
Ron
Jack
Paul

So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.

View 10 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Get Full Path Of File In C?

Oct 28, 2010

Is there a way to get the full path of a file in C? I have a method that accepts a file name as an argument and is supposed to read the content of the file. The file name might include "../" so this might lead to accessing files outside of the current directory. I tried to use fstat but I could not figure out how to get the full path.

[code]...

View 3 Replies View Related

Programming :: Set File Path For Different OS In Java

May 11, 2011

I'm fighting my way through JAVA. But have hit another wall. Basically I need to to set paths in java so it can set/read files/director for Linux,Mac and windows.

The tutorials I'm using says to do this through the FileSystems class eg

Code:

However this reports it is missing, so a look on line says I need the headers so I set them with

Code:

This gives the following error

This has me totally confused as the tutorial shows this and checking online shows this, do I need to link in libraries or something like that?

I'm using the latest Ubuntu 11.04 and netbeans.

View 4 Replies View Related

Programming :: Replace Spaces With Underscores In File Names?

Jan 11, 2011

I often get files with many spaces as part of their names. I would like to automatically replace these spaces with underscores, but otherwise not change the file name. Is there a way to do this task with just the bash shell?

View 4 Replies View Related

Programming :: Sed Doesn't Accept Variables To Replace In File

Mar 17, 2011

[code]...

The variables are clean and available in my script. No prob. $old is an IP-address of a server, $new as well. replacement-file is an xml-file (the ip-address to be changed is within an xml-tag). It should be trivial, but it isn't. I spent the last 3 hours reading about the problem, trying several different 'solutions' or workarounds. It should work, the '"' should take care that the variables get expanded, but whatever I try the old server IP isn't replaced.

View 7 Replies View Related

Programming :: Sed To Read The File And Replace And Insert The Pattern?

Jun 11, 2009

I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?

View 2 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 :: Replace A Hash In A Shadow File Not Using Passwd?

Aug 5, 2010

What is the easiest way to replace a hash in a shadow file for one particular user, not using passwd, and when the current password is unknown?

View 3 Replies View Related

Programming :: API To Get Partition Name Based On File Path In C On OS?

Jul 19, 2011

Is there any API to get partition name based on file path in C on Linux OS?

View 1 Replies View Related

Programming :: KSh Script - Assigning A File Path ?

Jul 25, 2011

I am assigning a file path to a variable like

$1 means it should accept some file name from cmd prompt but in my case its not working.

View 1 Replies View Related

General :: How To Replace The Path

Feb 16, 2010

I added a path in my bash_profile so that I could use the executables in the directory (I thought). But it turned out some other directory has the same executables and the path had already been added by the previous user. Is there way to overwrite this path? I can't find where that old path was added.

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

Programming :: Multi File Recursive Folder Search And Replace?

Aug 3, 2010

I'm wanting to mod some PHP files across a hierarchy and thought I'd drive it with find + grep + xargs

I built up a command line which I was confident would do the job, but now can't save the results.

First I tried this:

Code:
find . -name *.php | xargs grep serialize | cut -d: -f1| sort -u | xargs sed -i s/serialize/serialise/g
but that didn't work:
Code:
sed: illegal option -- i
so I thought I'd try using
Code:

[Code].....

View 10 Replies View Related

Programming :: Reading The Absolute File-path As Sorted?

Jun 13, 2010

I wanted to read out the absolute file-path (filename) as sorted in a folder (on Linux). The reading the file-paths is ok but I have problems in sorting.

Code:

selectedDirectory = fl_dir_chooser ("Select Imagedirectory:",NULL,0); //This is just a widget to show the folder.
DIR *d;
dirent *de;

[code]....

The files -105.dcm, -106.dcm, -107.dcm lie in the folder at the bottom and -36.dcm, -37.dcm- at the top. The program compares 1 and 3 of 105 and 37, 1 is lesser than 3, then prints out first, but does not know that 105 is three digits and 37 is two digits.

View 1 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 :: Rename File Names : Replace Dots By Spaces, Keep The Extension?

Mar 28, 2011

I am trying to rename a lot of files but need to keep the extension :

the files are films names :

a.b.c.d.***.iso

the result should be replacing "." by spaces " "

this command :

for files in *.iso ; do mv "$files" `echo "$files" | tr '.' ' '`; done

put a space also before the extension iso ??

How can I rename files from

"a.b.c.d.iso" to "a b c d.iso"

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

Debian Programming :: Copying A File Full Path Name To Clipboard

Jul 26, 2013

How do you set up a command just to copy a file's full path name (%F) onto the clipboard?(I can't seem to get this without copying the contents of the file.)

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







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