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


Programming :: Replace The Last Character String?

Jan 19, 2011

how to replace last character string. For example

$>export T1=abcde
$>export T2=xyz

how to get result abcdxyz?

View 10 Replies View Related

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:


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

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

Programming :: Sed - Replace Alternate Occurrences (on Different Lines)

Apr 15, 2011

I'm trying to process a postscript file and I want to change alternate pages by finding the string '%%EndPageSetup' (and then adding a line after it).

I've tried using sed with labels and a branching program to ignore the odd occurrences and process the even ones. In the code below I tried searching for the first and ignoring it by jumping to next and processing it and then to the next odd page and so on.

My logic is obviously flawed here as it doesn't work but I've tried the following:

sed -e '/%%EndPageSetup/{
b even
/%%EndPageSetup/ b even
s/%%EndPageSetup/%%EndPageSetup++/ b odd}' >

View 5 Replies View Related

Programming :: Input String Into Array Without Using Quotation Marks

Oct 11, 2010

I want to put a string, such as the one found in the image, into an array that will later be chopped into individual words and put into another array of individual words found in the initial string. (or, perhaps, I would be able to do that initially, but for now, that is the goal)My question is, how can I do that without using quotation marks?

View 5 Replies View Related

Programming :: S/ Command Won't Replace Two Occurrences Of Pattern On Same Line

Dec 15, 2009

Here's the actual line of code, which exists in a bash script:


I want to replace instances like this:


with this:


Using this:


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



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

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="''">/>/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 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:


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 to something else(, for example) without replace printera's accidentally?

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

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


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 :: Write A Function That Counts The Number Of Occurrences Of A Pair Of Letters In A String?

Sep 9, 2010

Some help with this problem:Code:Write a function that counts the number of occurrences of a pair of letters in a string

View 13 Replies View Related

Programming :: C++ Character Search In Text File?

Jun 23, 2011

Im trying to read a file in c++ and search for particular character for example if this is a list that I have:



if the input is D, it should give David, if its B, gives bob. so in this case, meaning it reads the first character of every line. but if possible I want to make this dynamic so the user can specify which character position he is looking for, so in case he is looking for R as character index 3 in all lines, it should give Charlie. but the problem is, it does now recognize , besides, I do not know how to specify the character position in each line.

here is my code


#include <iostream>
#include <fstream>
#include <cstring>


View 1 Replies View Related

Programming :: Sed To Change Character In Text File Only Once?

Sep 7, 2009

I have a script that looks like:


cat servers.txt


I want to be able to find the lines that matches my input and change the N to a Y, but only for the lines that matches the name and not any other N's My problem is the line does not always contain a P as it can be a D as well so my matching did not work. If my script issues the name $1=triva the lines will change to:



I have the following code so far but as you can see it does not change the D's


sed -i 's/trivia:P:Y/trivia:P:N/g' servers.txt

*** UPDATE ***

should I be using a method as follows? I am still stuck on the changing all instances though.


sed -i 's/$server1:P:Y/$server:P:N/g' server.txt
sed -i 's/$server1:D:Y/$server:D:N/g' server.txt

View 7 Replies View Related

Programming :: Read Only Quotation Marks Text

Apr 14, 2011

Columns are separated by SPACE. Column 5th is in quotation marks. How can I ask AWK to read everything between quotation marks ?

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 :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

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

Programming :: Shell Script Comparison For Two File(text) Character Wise?

Mar 1, 2010

I need to write a shell script which can compare two files(text files) character wise. eg. underscore is space.

------FILE 1---------------


Actual problem: I need to write a shell script which can give me difference character by character not by line (using comm)

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

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

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

View 1 Replies View Related

Programming :: String Format - Create A Text File ?

Feb 3, 2010

I am using C. I have a fuction that returns a string


I need to format this string so that I can create a text file like so:

So I'm trying:


But I get errors like:

View 2 Replies View Related

Programming :: String Search In Text File Using Visual C++

Jan 25, 2010

im tryin to make a tool in visual C++ which will take an input string through a text box,then it will compare tht string with a text file containing data and display the matched results in list box.

View 2 Replies View Related

Programming :: Sed Script - Searching For Text Within File / Replace With Variable

Feb 25, 2011

VARR=`cat /proc/asound/cards | grep HDMI | cut -c 1-2`
VARX="defaults.ctl.card $VARR"
VARY="defaults.pcm.card $VARR"
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 :: Script To Execute String From Text File

Sep 24, 2014

I am having trouble writing a script that monitors a text file. When the file contains number 1 (or any other string that is not a command) it does nothing, but when it is something different from 1, it executes that command.

So, there are 2 files: monitor.mon - this is the file that will be checked constanlty; and - the script that does the job. The monitor.mon file will have its content modified by php. This means a web page will have a form where I input commands and writes does commands in the file. will watch when the file's content changes from character 1 to a command, execute that command and write back a 1 so it will not execute it more times.

I tried combining while and if but with no success. Tried reading the file with cat and grep -e but it doesn't seem to recognize when content changes.

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


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

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


View 2 Replies View Related

Copyrights 2005-15, All rights reserved