I am trying to replace exact word from my text. I know using the angled brackets does the trick. But it is not working when there is a dot in the text.
But if my data has a dot or hash in it, it replaces all the occurrences of Bottle.
As you can see it is replacing all occurances of "Bottle" when there is a dot present.
The input data is not in my control. So I cant change or escape the characters.
Is there a way I can replace the exact match using sed, when a dot is present in the data?
I have to use Sed, since my code is generating a lot of sed text using -e options so I can run all of that in one go.
Right, I am aware of that Jim. But I want only the exact words to be replaced. Not all.
It should not remove the Bottle from "Bottle.Water".
Is there a way to tell sed to treat dots like underscores while searching?
Some versions of sed have options to use EREs instead of BREs which could shorten this considerably. Since you haven't told us what OS you're using, I'll give you the long, portable form (assuming your word delimiters are start of line, end of line, and space characters):
Last edited by Don Cragun; 03-19-2015 at 11:43 AM..
Reason: Change: -e '/s/^Bottle$//' to -e 's/^Bottle$//'
I am trying to replace exact word from my text. I know using the angled brackets does the trick. But it is not working when there is a dot in the text.
The escaped angle brackets (\< and \>) indicate a (left/right) word boundary in some versions of sed (alphanumeric characters plus _ (underscore)).
Since a dot is not a word character, "Bottle" will get replaced..
Last edited by Scrutinizer; 03-19-2015 at 02:11 AM..
Note, however, adjacent spaces in the input will be coalesced to a single space by the above command. For instance.
produces:
removing one space after the first two periods in the input string.
It isn't clear from the skimpy description of the desired results in this thread whether or not this is allowable. But, the request was for sed solutions only...
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
I have a workaround to the problem i m posting, however if someone wants to look at my query and respond ... i will appreciate.
This is in reference to this thread -> https://www.unix.com/shell-programming-and-scripting/267630-extract-between-two-exact-matched-strings.html
I have data.txt as... (11 Replies)
I would like replace all the rows in a file if a row has an exact match to number say 21 in a tab delimited file. I want to delete the row only if it has 21 any of the rows but it should not delecte the row that has 542178 or 563421.
I tried this
sed '/\<21\>/d' ./inputfile > output.txt
... (7 Replies)
This post was previously mistaken for homework, but is actually a small piece of what I working on at work. Please answer if you can.
QUESTION1
How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed.
Contents of car.txt
CAR1_KEY0
CAR1_KEY1... (2 Replies)
This was mistaken as homework in a different forum, but is not. These are questions that are close to what I am trying to do at work.
QUESTION1:
How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed.
Contents of car.txt
CAR1_KEY0
CAR1_KEY1... (1 Reply)
Lets say I have file.txt:
(Product:Price:QuantityAvailable) (: as delimiter)
Chocolate:5:5
Banana:33:3
I am doing a edit/update function.
I want to change the Quantity Available, so I tried using the SED command to replace 5, but my Price which is also 5 is changed instead.
(for the Banana... (13 Replies)
Dear Friends,
Anybody knows how to match exact lines only in multilinear.
Input file:
apple
orange
orange
apple
apple
orange
Desired output:
fruit
orange
apple
fruit
i used the command (1 Reply)
Hi,
Can anyone help me with the text editing I need here. I have a file that contains the following lines for example: (line numbers are for illustration only)
1 Hello world fantasy.
2 Hello worldfuntastic.
3 Hello world wonderful.
I would like to get all those lines of text that... (5 Replies)