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


ADVERTISEMENT

Software :: Replace A Text String In A File With A Random String - With Sed ?

Sep 2, 2010

I have a line in a text file that has 40 random characters within a tag and i want to change the characters to a new set of 40 random characters (alphanumeric a-z 0-9 etc)

The line in the text file looks like this:

Quote:

How would i go about doing that?

Also second question same as the above but how would i remove them instead of replacing them?

View 14 Replies View Related

Fedora :: Replace A String By A String In Text File?

Apr 26, 2011

If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?

I am using vi editor.

View 3 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 :: 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 :: Using Sed Replace Line Containing Particular String By A Single String?

Oct 16, 2010

I have a set of lines as ahown below:

Leon went to school
Leon came back from school..
Leon had dinner...

I have to replace the line containing "dinner" by a single string LUNCH...

View 2 Replies View Related

General :: Perl Command To Replace String By Line Numbe?

Jul 10, 2010

I want to know the Perl command to replace a string by pointing the line number. I know how to replace a string without pointing a line number but I am in need to replace only the two matching string in a file

View 6 Replies View Related

Programming :: Reading In A Outside Text File And Putting In The String On That Line Into A Char Array That Is Already Allocated?

Mar 29, 2011

Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.

Code:
int main(int argc, char *argv[])
{

[code]....

View 1 Replies View Related

Software :: Best Software To Replace A String In A Big Text File?

May 22, 2011

I have a big text file (350mb) and i need to replace some strings in it.

The VIM is too slow. Also I don't need to open file and view its contents. I just need to give the command to replace it for faster processing.

Which software would be the best for this purpose?

View 7 Replies View Related

Ubuntu :: Replace A Line Containing Particular String Using Sed?

Oct 16, 2010

How to replace a line containing some word by only another word...

Ex: The sed program is the Linux stream editor utility The pattern is a regular expression that you wish to match and replacement is the new string to ..

replace the line containing 'program' by only word LINUX

View 1 Replies View Related

General :: Using Sed To Replace String With Special Characters In XML File?

Apr 29, 2011

I am having difficulty getting sed to replace a string of text in an XML file, despite the fact that I have no trouble using grep to find that same string. Since the new string and old string to be replaced contain a lot of special characters, I thought it best to store them in variables as opposed to using a slew of backslashes:

OLD_STRING='<property name="webServiceHost">${jboss.bind.address}</property>'
NEW_STRING='<!--<property name="webServiceHost">${jboss.bind.address}</property>-->'

[Code]....

View 2 Replies View Related

General :: Replace A String In Multiple File & Sub Directories?

Aug 31, 2010

Need to replace the following string :

By

In multiple .exp files and in sub directories.

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

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

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

Programming :: Replace An "entire" Line Containing A Particular String With A New Line?

Mar 12, 2010

I think this can be done using sed. Let's say I have file called, "orig.txt" with following contents:

Code:
[User Prefs]
Ignore Unrequested Popups=1
DevTools Splitter Position=500
History View Style=0

[Code]....

So basically if a line contains the word "Home URL" then go ahead and replace that *entire* line with the supplied *new* line.

View 4 Replies View Related

General :: Replace String With Empty String Of Dir Path ?

Apr 2, 2011

I want to replace a string of directory path in a string to empty:

Code:

But this doesnt seem to give me the desired thing:

Code:

This gives the desired outcome, but its specific, i need a variable in the sed not a string. And if I replace STRING="/mnt/sda1/record/$dd/" then I cant use it for something else, cause its has all the weird backslashes now.

View 3 Replies View Related

General :: Replace One Line For Another In File?

Dec 1, 2010

I trying to change a file with hundreds of entries, replacing line with "IP Address Number" for "Host Name", one for another.

this is the original: [IP Address Configuration : "172_17_27_161.SUBNET_U"] IP Address Number = 172.17.27.161Assignment Type = 8Host Name = CAST124Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59and the result desired is: [IP Address Configuration : "172_17_27_161.SUBNET_U"]Host Name = CAST124Assignment Type = 8IP Address Number = 172.17.27.161Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59I know how to change one character by another with sed, but not to change a line for another, because I don't know in which line number it is.

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

General :: Get The Shortest String In A Text File With Shell?

Apr 29, 2010

Assume I have a text file as belowabcdaaaaaaagfgkhahahahahahhahhgfThen gf would be returned

View 4 Replies View Related

General :: Find Text After String Search In File

Aug 2, 2011

I have a file called Regions.ini that looks like this:

Code:
[Granite]
RegionUUID = 54ab7cd2-0e70-49b7-8020-8dbeb84c08d0
Location = 9991,10007
InternalAddress = 0.0.0.0
InternalPort = 9001
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9

[Syenite]
RegionUUID = 8fc56fdd-0afd-4074-9432-0ae8f42b799f
Location = 9992,10007
InternalAddress = 0.0.0.0
InternalPort = 9000
AllowAlternatePorts = False
ExternalHostName = 71.171.21.9
What I need to do is find out what the IP address is after "ExternalHostName ="

After that I will need to compare that IP to whatismyip and if it's different then replace it but that is easy to do with sed. I just can't figure this simple hurdle out.

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

General :: Ubuntu - Replace A File In Jar With Command Line ?

Oct 18, 2010

I have a jar, and I need to replace a class in it, at this moment, I can only open it with "archive manager" and then drag and drop the new compiled class into the jar, but I think this is really boring, if I can do with with just a command ?

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

General :: Use The Diff Command To Get The Difference Between A String Of Text And The Contents Of A File?

Mar 31, 2010

I am not especially cli adept so could someone tell me the best way to use the diff command to get the difference between a string of text and the contents of a file instead of between the contents of two files?

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

General :: Sed/awk/grep Search For Number String Of Variable Length In Text File?

Jan 19, 2010

I need to search a text file for a string of numbers which are different lengths, and always are between number=" and " like:

number="1234567890"
number="22390"

I need to grab those numbers and pipe each one to a line in a file. I've already tried something with awk and that didn't seem to work.

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







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