01-10-2011
SED to replace exact match, not first occurrence.
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 case, if I were to replace 3 with 5, my price will be 53 because it replaced the 3 which comes first)
Is there a way to only replace data within the Delimiter?
Or rather, how should I go about solving this?
Thanks in advance!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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)
Discussion started by: vasanth.vadalur
1 Replies
2. Shell Programming and Scripting
Hi, i have file f1.txt with data like:
CHECK
a
b
CHECK
c
d
CHECK
e
f
JOB_START
....
I want to match the last occurrence of 'CHECK' until the end of the file.
I can use awk:
awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2Is there a cleaner way of... (2 Replies)
Discussion started by: ysrini
2 Replies
3. Shell Programming and Scripting
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
CAR2_KEY0
CAR2_KEY1
CAR1_KEY10
CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1
grep... (1 Reply)
Discussion started by: thibodc
1 Replies
4. UNIX for Dummies Questions & Answers
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)
Discussion started by: thibodc
1 Replies
5. Shell Programming and Scripting
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)
Discussion started by: thibodc
2 Replies
6. UNIX for Dummies Questions & Answers
hey guys, i have been trying to work this thing out with sed with no luck :confused:
i m looking for a way to replace only the first occurrence after a match
for example :
Cat
Realized what you gotta do
Dog
Realized what you gotta do
Sheep
Realized what you gotta do
Wolf
Realized... (6 Replies)
Discussion started by: boaz733
6 Replies
7. Shell Programming and Scripting
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)
Discussion started by: Kanja
7 Replies
8. UNIX for Dummies Questions & Answers
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.
echo "Bottle BottleWater Bottle Can" | sed 's/\<Bottle\>//g'
BottleWater CanBut if my data has a dot or hash in it, it replaces all the... (10 Replies)
Discussion started by: grep_me
10 Replies
9. UNIX for Dummies Questions & Answers
Hi all,
I have an input file as below. I would like to count the occurrence of pattern matching 8th field for each line.
Input:
field_01 field_02 field_03 field_04 field_05 field_06 field_07 field_08
TA T TA T TA TA TA... (3 Replies)
Discussion started by: huiyee1
3 Replies
10. Shell Programming and Scripting
Hi, i have file file.txt with data like:
START
03:11:30 a
03:11:40 b
END
START
03:13:30 eee
03:13:35 fff
END
jjjjjjjjjjjjjjjjjjjjj
START
03:14:30 eee
03:15:30 fff
END
ggggggggggg
iiiiiiiiiiiiiiiiiiiiiiiii
I want the below output
START (13 Replies)
Discussion started by: Jyotshna
13 Replies