Please remove 'g' at the end of your sed command.
g means globally. The change will effect to all entries.
If you remove g , it will change first occurence.
---------- Post updated at 08:36 AM ---------- Previous update was at 07:54 AM ----------
Oh, actually, I want to use sed to find the specific line that fulfills the requirement of $BookTitle:$BookAuthor. So if I were to update the value of $BookAuthor, it must update according to the $BookTitle.
E.g.
The Book Author is J.K. Rowling
There are various books by J.K. Rowling:
Philosopher's Stone:J.K. Rowling
Chamber of Secrets:J.K. Rowling
Prisoner of Azkaban:J.K. Rowling
The code below only takes the first entry "Philosopher's Stone:J.K. Rowling" and replaces it with the new author.
So it changes Philosopher's Stone:J.K. Rowling to Philosopher's Stone:Candace
However, I want to be able to update $BookAuthor based on the value of $BookTitle.
For example, I want to be able to change Chamber of Secrets:J.K. Rowling to Chamber of Secrets:Candace.
Use sed's address capability to find the line and then replace old author with new:
@karumudi7: g means all occurrencies in that respective line, NOT in entire file!
Okay, I think I should specify my question further.
I need to be able to update the values of a specific value in my .txt file.
For example: [fruit]:[brand]:[price]:[qty]
apple:greenwood:0.70:50
pear:sunshine:0.95:60
dragonfruit:moonshine:1.50:50
If I do a search for apple and greenwood, I should be able to update the fruit, brand, price, and qty of that entry. So lets say I did a search (fruit & brand) on pear & sunshine. I'll be able to update the value of pear, sunshine, price, and quantity.
This is what I've done so far, but as per my problem above, I'm unable to update specific values in a specific entry.
Fruit & Brand variables will remain as constants to match with the .txt file.
I'm figuring there will be 4 different codes for the updating of 1) fruit, 2) brand, 3) price and 4) qty. Sed is confusing me with all the pattern flags and command line options.
P.S.: I tried using grep from my .txt source, and pipe it into a do-while loop, but I'm still unable to update the specific values.
Last edited by todaealas; 01-12-2013 at 10:00 AM..
I have the input file like this.
Input file: 12.txt
1) There are one or more than one <tr> tags in same line.
2) Some tr tags may have one <td> or more tna one <td> tags within it.
3) Few <td> tags having "<td> </td>". Few having more than one " " entry in it.
<tr> some td... (4 Replies)
file1
cat
dog
fish
file2
This is a bunch of lines
<!-- INSERT ANIMALS HERE -->
horse
cheetah
post results
file2
This is a bunch of lines
<!-- INSERT ANIMALS HERE -->
cat
dog
fish
horse (1 Reply)
Hey Guys and Gals,
I am having trouble with what I thought shouldn't be hard..
In a script I am working on there is a need to enter a MAC address.
MAC addresses are formatted ;
XX:XX:XX:XX:XX:XX
where X can be 0-9, a-f or A-F
So in the sample script the query is something... (4 Replies)
Hi,
I have a text file which is output from a server and it lists all the files in a specific volume. However, the volume name appears as volume_name:.
I would like to replace this with \\volume_name\volume_name. This is not a problem in itself as I can use sed to globally look for the... (8 Replies)
Hello All,
can someone please suggest me a one line command to change a specific value that is associated to an entry in the file.
for example
#more schedulefile
quartz.job.manual.bonus.schedule=0 0 9 ? * *
#
it should be changed to
#more schedulefile... (5 Replies)
I need to get notification via email when the line containing a pattern is changed in a file. Not during the time any changes to file occurs. Ie if we reset a user password say example, demouser the hash in the line containing the word demouser in the file /etc/group changes. So when this change... (1 Reply)
Hi friends,
This is sed & awk type question.
I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example
###start of input text file ####
abc
def
ghi
1
2
3
4
kjld
random... (3 Replies)
sed -e "s// /g" old.txt > new.txt
While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Hi,
I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ".
File.name.is.long.ext -> File name is long.ext
I can get the desired effect with
echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Hi there
I have a file which has the lines
# Serial number for hostid
EXP_SERIAL_=""
These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with
# Serial number for hostid $var1
EXP_SERIAL_$var1="$var2"
Is there a quick and simple... (6 Replies)