Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
1answer
39 views

Stuck With Using find and sed to Replace String in Filenames

Following this post as a reference, I'm able to run a find and sed command without it throwing an error, but the filenames remain unchanged. Trying to strip pronunciation_de_ from all mp3s in the ...
1
vote
2answers
32 views

Mass folder name correction - Calibre

I allowed Calibre access to my Library and it decided to change all my folder names adding (123) after every folder. (Replace 123 with random numbers.) What would be best command to use on Linux (...
1
vote
1answer
34 views

Odd behavior (bug?) of sed when using $

I've got a problem and I am not sure whether this is a bug or if this is supposed to happen when using $ for addressing lines. Basically, I have the following command: sed -e '$s/test/tset/g' ...
0
votes
1answer
27 views

Simple Binary Replacement

I tried using bbe as below bbe -e 's/01110011/01111000/' test.txt All I'm trying to accomplish in this example is to read the file as if it's a binary file, and replacing the letter s with x. I'm ...
0
votes
2answers
25 views

Storage disk info - Replace multiple Input values to output file

I would like replace below input about storage disk to an output in below presented format: Below script is almost working for me. But it doesn't work for T0. It seems is there problem with proper ...
1
vote
1answer
25 views

Delete groups of lines that have the same first line, except for the first occurence

This may be a couple questions in one, but this problem has me stuck. I have a text file with groupings of four lines separated by an empty line. The first line of every grouping begins with a '>' ...
2
votes
3answers
130 views

Replace string 1 only when string 2, 3, or 4 present

Basically I am an oracle dba. We have a task to switch-over from primary db to standby db and we need tns entries (host-name) to be modified from sape-scan to sapi-scan in the tnsnames.ora file ...
2
votes
3answers
1k views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
1
vote
2answers
63 views

How to Replace 3rd column (until a specific char) in a file from another file

I have two files: bor.mol2 and bor.com In bor.mol2, there are X,Y,Z coordinates of atoms between @<TRIPOS>ATOM and @<TRIPOS>BOND keywords in this file 3th, 4th and 5th columns are ...
10
votes
5answers
35k views

Sed : Replace pattern on every second newline?

Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to). Edit ...
1
vote
4answers
61 views

Replace string in multiple files (same directory) with condition

Example: File1: Name: abc Number: 325 Code: 0 File2: Name: xyz Number: 578 Code: 0 File3: Name: ttt Number: 356 Code: 0 File4: Name: nnn Number: 228 Code: 0 File5: Name: bnb Number: 434 Code:...
0
votes
2answers
35 views

Replacing string in file with MAC OSX

I need to replace a string in a (large) file on a MacOSX 10.10. My file looks like this: Y16-TUL-SUB_ Y16-TUL-SUB_ Y16-TUL-SUB_ Y16-TUL-SUB_ Y16-TUL-SUB- Y16-TUL-SUB_ Y16-TUL-SUB_ and I need to ...
0
votes
1answer
25 views

I am not able to update a variable through sed command

I have assigned two variables but not able to update x=$(cat /scratch/env.properties | grep ConfigPath) y=$(ConfigPath=/scratch/a/b) then sed to replace ConfigPath in env.properties sed 's/$x/$y/' ...
2
votes
4answers
75 views

Parse a csv file, replace separator, ignoring the content of fields between “ ”

I have a file with ; separators ; my application parses the data, based on those separators. String fields are between "" and in columns, I might have the separator as text. I would like to replace ...
0
votes
2answers
47 views

Why is my multi-line perl string replace adding a blank line?

I'm trying to replace multiple lines in a text file (an XML element with an unknown number of children) with the contents of a separate text file. I've managed to get the replace mostly working using ...
0
votes
3answers
57 views

How to find and replace seemingly a tab char using sed?

I have a line looks like this: some.com *.some.com The space is seemingly a tab space because when I move the keyboard arrow, one move will move me to the end of it (it does not seem multiple ...
0
votes
1answer
23 views

How to express beginning and end of line in sed

I want to use sed to replace every '} that comes at the end of the line to "}. I wrote: sed -i -e "s/'}$/\"}$/g" But this replaces it to: "}$. What is wrong? How can I use regex in my sed to express ...
0
votes
1answer
30 views

How to search for a newline that is not preceeded by } and remove it

I want to use sed to search for line breaks that are not preceded by }. The regex for identifying theses cases is: [^}]$ . What I want to say: If the line ended without } then remove the new line. ...
1
vote
2answers
3k views

How do you search and replace multiple lines in KDE Kate?

how do you replace multiple lines of code in Kate? The following is the original text: <div id="image"> <br style="clear: left"/> <br style="clear: left"/> <br style="clear: ...
0
votes
3answers
56 views

How to keep the content of a replaced string with sed

I am trying to use sed to replace a line of text that will keep the found text intact and add a colon to the end of it. specifically, in a file there are a bunch of lines in this format ...
1
vote
3answers
32 views

Can I replace multiple characters in ed?

I have a text 'ab' whose content is composed of a,b letter. I want to change a to b, b to a at once by using s command in ed. But if I change them step by step, as you know, all the text will be ...
1
vote
4answers
514 views

Bash command to “search and replace” file in changing directory tree

I've built a collection of files for research in a central repository on my server. I'm continually curating the repo changing the directory's tree structure by renaming and moving directories. And I'...
7
votes
2answers
2k views

shell script/utility replace 2 byte unicode in binary file

I have many large Unicode files. I would like to replace each Unicode byte pair with a new Unicode byte pair. For example, the original file contains "C3 B9 C3 AB C3 B8 C3 B0" and I would like to ...
0
votes
3answers
345 views

replace everything and move word to end position

maybe my question should answered in two ways but I hope it could be done with in one "sed": I have the following lines, with different IDs: ID1_TRINITY_DN120587_c0_g1::TRINITY_DN120587_c0_g1_i1::...
5
votes
2answers
8k views

use awk to replace parentheses?

How can I use awk to replace the parentheses in these 2 scenarios? Change empty parens to the word "None" 192.168.0.24,Up,() Remove parens to only host.domain.com is left 192.168.0.25,Up,(host....
7
votes
1answer
299 views

Is it possible to replace duplicates of a character with one character using tr

I'm trying to take all occurrences of # and if they are consecutive replace them with just one #. e.g. ab ### cde fghi## jklm would become: ab # cde, fghi# jklm My initial goal was to replace ...
1
vote
2answers
16 views

How to replace patterns in files contained in a list of files?

I have a text file fileslist containing a list of names of files, or rather relative paths to those files and their names from a certain parent directory. There is only one file per line in fileslist. ...
78
votes
11answers
37k views

vim - how can i do a 'change word' using the current paste buffer

I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer. I now go to the word 'bar' and I want to replace it with my paste buffer. To replace the text ...
1
vote
3answers
735 views

How to search and replace a string with newlines on commandline in a file

I want to replace all occurrences of a text string in a textfile on command line on CentOS 7.2. Search-string: ).\nPORT Replacement-string: ). \n0 closed ports\nPORT I know, this can be achieved ...
-3
votes
1answer
39 views

awk query for sequential replace a pattern

I found the below awk command to sequentially replace a particular line in a file, but i would like to know how this works. Input:- DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 output:- DS: 1 DS: 2 ...
1
vote
2answers
447 views

replace a block of text with the contents of a file

I would like to replace the contents between $Elements$ and $EndElements$ in text file, f1, with the data from another file, f2. The contents of f1 is given simply by $Elements$ 3 1 5 7 $EndElements$...
24
votes
7answers
8k views

How to replace current word under cursor in Emacs

How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. ...
2
votes
2answers
262 views

Bash replace string at multiple places in a file from command line

I have a file with the below content. I want to replace chrome with chromeBackup but not in all places. Name=chrome XXXXXXXXXXX Run=bin -app "chrome/chrome.sh" XXXXXXXXXXX Vol.apps/chrome=chrome ...
1
vote
2answers
79 views

sed: strip enclosing square brackets

I have this file: [default] region = us-east-1 output = json [profile automation] region = us-east-1 output = json [profile qa] region = us-east-1 output = json I need to extract only the profile ...
1
vote
2answers
242 views

btrfs replace on RAID1 is super slow with failed disk present

I'm trying to replace a failed disk in a RAID1 btrfs filesystem. I can still mount the partition rw (after about 5 minute delay and lots of I/O kernel errors). I started replace with -r in an ...
3
votes
3answers
534 views

Can I reboot during a btrfs replace and then resume it?

I have a damaged hard disk with a lot of read errors. I'm currently doing a btrfs replace, but after 24 hours at just over 5% done, this is a problem: it's my work computer; I'm currently booted onto ...
4
votes
4answers
4k views

Btrfs RAID1: How to replace a disk drive that is physically no more there?

I have a btrfs RAID1 system with the following state: # btrfs filesystem show Label: none uuid: 975bdbb3-9a9c-4a72-ad67-6cda545fda5e Total devices 2 FS bytes used 1.65TiB devid 1 ...
0
votes
1answer
45 views

korn shell Unable to substitute ' ' (2 quotes) with ' (single quote) in a string variable

I am trying to substitute ''2019-01-14'' to '2019-01-14' in a varible $STG. I tried various techniques echo ${STG//''/'} echo $STG | sed -e s/'\'\''/'\''/g many more none of the equations are ...
-1
votes
3answers
99 views

how to find & replace a file path listed in a file

I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep ...
-3
votes
1answer
67 views

How to replace value in each field until a certain character in each record?

Each record coming with column names. I have to replace them in each record as shown below: TIME=20181219110000275|CHAN=FMBKHJBAAAADPCFNAAAAAABA|EVNT=SWIgrld|API=SWIrecGrammarActivate|TYPE=uri/2.0|...
1
vote
4answers
249 views

sed find and replace html tag

I need find and replace in a md file (plain text) <span class="symbol">&#58771;</span> with this: [&#58771;]{custom-style="symbol"} I tried many times, f.e. sed -i -e 's/\(&...
3
votes
4answers
220 views

Replace a string in a file preceeded by another string

I have a bunch of config files looking as follows: reader_0 = newcamd({ name = "Oct 1", host = "hostname 1", port = 27020, user = "UNAME", pass = "password1", key = "0102030405060708091011121314", })...
1
vote
1answer
37 views

How to prevent from destroying symlinks, using Perl when to replace with sed regex?

Based on How do I prevent sed -i from destroying symlinks?, but I use Perl. I tried by middle of all these questions: Is there a way to make perl -i not clobber symlinks? perl symlink on gz file How ...
-1
votes
1answer
180 views

how to find and replace a string containing “/” [duplicate]

currently I have faced a problem in changing a string in a file which have / character . I want to replace 1/0 with hetero in a file. can you tell me which command to use ?
0
votes
1answer
282 views

How to replace double new line with single using tr?

Given a text, $ cat a.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor vitae. Etiam iaculis ...
0
votes
2answers
45 views

Multiline string replace inside markup tag

I am trying to modify an httpd.conf file, allowing override in the /var/www/html directory. For simplicity's sake, let's say it looks like this: <Directory "/var/www/html"> # Comment ...
1
vote
0answers
46 views

Two replacements in one go [duplicate]

How do I go about replacing one character for another and then another character for another in one line and printing the result? As an example, consider the following code: string="1 33 4 a" echo ${...
0
votes
2answers
1k views

Search and replace specific tag value in XML file with sed command

I have a task where by I have to manipulate an XML file through a bash shell script. Here are the steps: Query XML file for a value. Replace the value of a different element with the new value. ...
0
votes
3answers
2k views

Find and replace with filename

I have a large number of files which contain text. All files contain the word "replace" (no quotes). I would like to replace that word with the name of the file. Example, filename is: On Time.txt ...
3
votes
1answer
320 views

Bash string range and replace

To print part of the string, replace , with . I use command: echo "${q:16:6}" | sed 's/,/./' Is it possible to use something like: echo "${q:16:6/,/.}" because it does not work?