01-21-2009
String replacement
Hi I am new to shell scripting but i manage to do some simple things.
I am trying to replace a string in one file. I am using sed to replace but it is not permanently writing to the file, rather it is temporary. I want to know whether is there any another method to replace a string in a file permenantly.
THIS IS WHAT I HAVE DONE:
=====================
$ cat conf.txt
This is first line which contains NO
This is second line which contains NO
This is thrid line which contains NO
I used sed to replace NO with YES in 2nd line.
$cat -n conf.txt | grep 2 | sed 's/NO/YES/g'
2 This is second line which contains YES
But i want this to happen in the file. I want the replacement to be happened in file(2nd line though).
Please guide me regarding the same and correct me if iam wrong.
Thanks in advance.
ss
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi guys, I hope you can help me with my problem.
I have a text file that contains lines like this:
78 ANGELO -809.05
79 ANGELO2 -5,000.06
I need to find all occurences of amounts that are negative and replace them with x's
78 ANGELO xxxxxxx
79... (4 Replies)
Discussion started by: amangeles
4 Replies
2. Shell Programming and Scripting
Okay, I have a script right now that is made to search through a file and replace certain strings with a new one. The format to execute is "/subst <replacethis> <withthis> <filename>" and it only updates the file IF changes are made (in order to preserve the time it was made/last modified). I have... (6 Replies)
Discussion started by: jbud
6 Replies
3. Shell Programming and Scripting
I have an xml file with following tags
<NewTag>value123</xyz>
<NewTag>value321</abcd>
I have to replace the values in between the tags with some value ( VAL1/VAL2)
but the thing the ending tag can be any thing, for this i need a awk command
currently i am using this but it... (5 Replies)
Discussion started by: subin_bala
5 Replies
4. Shell Programming and Scripting
Hi
I have a text file which contains the following.
AAA,BBB,CCC,DDD
AAA,BBB,CCC,DDD
AAA,BBB,CCC,DDD
How can I replace all CCC with 888, with other contents inside the file remain unchange? Please advice
Desired output:
AAA,BBB,888,DDD
AAA,BBB,888,DDD
AAA,BBB,888,DDD (1 Reply)
Discussion started by: c0384
1 Replies
5. Shell Programming and Scripting
I have one string
string1=user/password:IP_ADDR:Directory
I need to replace string1 value like store into string2
string2=user password:IP_ADDR:Directory
i.e replace "/" character by '<space>' character
But i wouldn't use any file in the meantime.
Please help me......................... (6 Replies)
Discussion started by: mnmonu
6 Replies
6. Shell Programming and Scripting
I need to search and replace a particular string in a file. Only the exact match of the string should be replaced.
eg: File contents : abc abcd abcdef
--> Replace only 'abc' with 'xyz', but it should not replace abcd with xyzd.
So the o/p should be: xyz abcd abcdef.
How can this be done? I... (5 Replies)
Discussion started by: sngk
5 Replies
7. Shell Programming and Scripting
Hi All,
I have below file which has data in below format.
#$ | AB_100
| AB_300
()| AB_4
@*(% | AB-789
i want o/p as below format.
| AB_100
| AB_300
| AB_4
| AB-789
So here there is no standard format.
How we can achieve the same in unix ?
Regards, (3 Replies)
Discussion started by: gander_ss
3 Replies
8. Shell Programming and Scripting
Dear Friends,
I want to replace following line with given line.
It should grep/search following string in a file (input.txt)
M/M SRNO: 000M/6200-0362498 COSMETIC PRO MALE FEMALE
Once found it should replace it to following string.
T_DLHNNO: 000M/6200-0362498 ... (7 Replies)
Discussion started by: anushree.a
7 Replies
9. Shell Programming and Scripting
Hi,
I have a text file where all records come in one line (single line file), each record starts with 'BUCH' and ends with '@&' and if data is not there we get space instead. between '@&' and next record there might be some spaces, now I want to remove those spaces between '@&' and 'BUCH'.
... (4 Replies)
Discussion started by: maks475
4 Replies
10. Shell Programming and Scripting
Hi,
Using the following command, I can only get rid of the last extension from my input file name:
parallel command '>' {.}.output ::: my.input.file
The output file is "my.input.output"
How can I get rid of the last two extensions of my input file name, so that end up with "my.output"?... (4 Replies)
Discussion started by: forU
4 Replies
LEARN ABOUT XFREE86
git-replace
GIT-REPLACE(1) Git Manual GIT-REPLACE(1)
NAME
git-replace - Create, list, delete refs to replace objects
SYNOPSIS
git replace [-f] <object> <replacement>
git replace [-f] --edit <object>
git replace [-f] --graft <commit> [<parent>...]
git replace -d <object>...
git replace [--format=<format>] [-l [<pattern>]]
DESCRIPTION
Adds a replace reference in refs/replace/ namespace.
The name of the replace reference is the SHA-1 of the object that is replaced. The content of the replace reference is the SHA-1 of the
replacement object.
The replaced object and the replacement object must be of the same type. This restriction can be bypassed using -f.
Unless -f is given, the replace reference must not yet exist.
There is no other restriction on the replaced and replacement objects. Merge commits can be replaced by non-merge commits and vice versa.
Replacement references will be used by default by all Git commands except those doing reachability traversal (prune, pack transfer and
fsck).
It is possible to disable use of replacement references for any command using the --no-replace-objects option just after git.
For example if commit foo has been replaced by commit bar:
$ git --no-replace-objects cat-file commit foo
shows information about commit foo, while:
$ git cat-file commit foo
shows information about commit bar.
The GIT_NO_REPLACE_OBJECTS environment variable can be set to achieve the same effect as the --no-replace-objects option.
OPTIONS
-f, --force
If an existing replace ref for the same object exists, it will be overwritten (instead of failing).
-d, --delete
Delete existing replace refs for the given objects.
--edit <object>
Edit an object's content interactively. The existing content for <object> is pretty-printed into a temporary file, an editor is
launched on the file, and the result is parsed to create a new object of the same type as <object>. A replacement ref is then created
to replace <object> with the newly created object. See git-var(1) for details about how the editor will be chosen.
--raw
When editing, provide the raw object contents rather than pretty-printed ones. Currently this only affects trees, which will be shown
in their binary form. This is harder to work with, but can help when repairing a tree that is so corrupted it cannot be pretty-printed.
Note that you may need to configure your editor to cleanly read and write binary data.
--graft <commit> [<parent>...]
Create a graft commit. A new commit is created with the same content as <commit> except that its parents will be [<parent>...] instead
of <commit>'s parents. A replacement ref is then created to replace <commit> with the newly created commit. See
contrib/convert-grafts-to-replace-refs.sh for an example script based on this option that can convert grafts to replace refs.
-l <pattern>, --list <pattern>
List replace refs for objects that match the given pattern (or all if no pattern is given). Typing "git replace" without arguments,
also lists all replace refs.
--format=<format>
When listing, use the specified <format>, which can be one of short, medium and long. When omitted, the format defaults to short.
FORMATS
The following format are available:
o short: <replaced sha1>
o medium: <replaced sha1> -> <replacement sha1>
o long: <replaced sha1> (<replaced type>) -> <replacement sha1> (<replacement type>)
CREATING REPLACEMENT OBJECTS
git-filter-branch(1), git-hash-object(1) and git-rebase(1), among other git commands, can be used to create replacement objects from
existing objects. The --edit option can also be used with git replace to create a replacement object by editing an existing object.
If you want to replace many blobs, trees or commits that are part of a string of commits, you may just want to create a replacement string
of commits and then only replace the commit at the tip of the target string of commits with the commit at the tip of the replacement string
of commits.
BUGS
Comparing blobs or trees that have been replaced with those that replace them will not work properly. And using git reset --hard to go back
to a replaced commit will move the branch to the replacement commit instead of the replaced commit.
There may be other problems when using git rev-list related to pending objects.
SEE ALSO
git-hash-object(1) git-filter-branch(1) git-rebase(1) git-tag(1) git-branch(1) git-commit(1) git-var(1) git(1)
GIT
Part of the git(1) suite
Git 2.17.1 10/05/2018 GIT-REPLACE(1)