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 '>' ...
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 ...
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
3answers
56 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. ...
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 ...
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 ...
7
votes
1answer
298 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. ...
-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 ...
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
240 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 ...
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
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 ...
0
votes
1answer
280 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 ...
-1
votes
3answers
97 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|...
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. ...
3
votes
1answer
318 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?
0
votes
3answers
42 views

How to replace a number by its corresponding string (low/high) in bash?

I have a file: property(Address1, 4.5) property(Address2, 2.2) property(Address3, 9.0) property(Address4, 3.4) --- I want to replace the floating points based on some conditions (For example: if the ...
0
votes
1answer
32 views

find and replace a substring and change to uppercase

I think it's best done with an example Contents of my file name="apple" parameter1="value1" parameter2="value2"; name="orange" parameter1="value1" parameter2="value2"; name="tea" parameter1="value1" ...
0
votes
2answers
237 views

Replace different strings based on a match by a list of strings in another file

I have a file like this with tab delimiter: Chr1 mak gene 120221 120946 . + . ID=spa-h0003.02;Name=spa-h0003.02 Chr1 mak mRNA 120221 120946 . + . ...
0
votes
1answer
399 views

Using sed to replace periods with single spaces to periods with double spaces [duplicate]

What command would you give to print (display on the screen) the corrected text of userNotes.txt with all sentence endings having required two blanks before the start of the next sentence? This is ...
0
votes
2answers
37 views

How do I use different replacement texts for a pattern found multiple times [duplicate]

sample log file: apple AAA rose banana AAA tulip orange AAA marigold replacement-text file: 111 222 333 Expected output: apple 111 rose banana 222 tulip orange 333 marigold
0
votes
2answers
210 views

sed with variables containing /

i have a text file containing some content like that, some content replace content other content and i have some variables, looking like this: PATH="/path/to/scriptdir" PARAMETERS="para1 ...
2
votes
3answers
70 views

Conditionally replace lines of file1 with the corresponding lines of file2

For example, I have two files: file1: 1 4 X 5 X 7 file2: 2 3 5 X X 1 I want to replace X-lines of file1 with whatever is in file2 on the corresponding line: result: 1 4 5 5 X 7 I prefer the ...
-1
votes
2answers
105 views

Replace iteratively with things contained in array

foo bar, foo bar, foo bar foo bar Given this beautiful poem, how could all the bar be replaced by superman, but each time with a different ending, contained in an array (is super, is blazing fast, is ...
2
votes
3answers
263 views

Replacing two patterns in a text files at the same time [duplicate]

I have a text file contain numbers as follows: 34 77 1716 150?.2 67.5892 11.9691 23 1?6 83 35 78 0 0 0 0 0 0 0 36 79 0 0 0 0 0 0 0 37 80 0 0 ? ? 0 0 0 38 81 0 0 0 ? 0 0 0 39 82 0 0 0 0 ? 0 ? 40 85 ...
0
votes
3answers
104 views

Replace text with another

I would like to replace a string with another string. For example: I would like to change the following text: "listen_addresses = ['127.0.0.1:53', '[::1]:53']" to the following text "...
-2
votes
1answer
36 views

Replace string in one file with contents of another file when match column

I have two files like: file 1 : a stringori to replace, this stringori comme again other stringori2 to replace, stringori2 commes again ... file 2: stringori newstring stringori2 newstring2 ... ...
2
votes
6answers
258 views

How can I operate on \1 in sed (or $1 in awk)?

I have file with several lines. Each with a timestamp followed by text: 1534888050 some text 1534888051 some more text 1534888052 text ... and want to convert the timestamp to a readable format, ...
0
votes
3answers
72 views

Recursively find and replace contents of one file using a key from another file

I need to use one file as an input to find and replace in another file. The following command does so, but only for the first column for each line. I need this to happen for every column. awk -F',' '...
1
vote
1answer
49 views

preg_replace for replacing comment text in a file

In a file, I want to replace COMMENT AS `<some_comment>` with COMMENT '<some_comment>' That is, replace COMMENT AS with just COMMENT, and replace the backticks around the following ...
8
votes
4answers
400 views

Rename multiple files with 2 conditions/replacements in one line?

I'm trying to rename a few images: IMG_1.JPG IMG_2.JPG IMG_3.JPG I want to replace IMG with img and .JPG with .jpg - I know how to do the second part: $ rename 's/\.JPG$/\.jpg/' *.JPG My problem ...
1
vote
2answers
190 views

Bash replace string with command

I have a command (logcat) which outputs a long log like this: 07-27 09:26:22.416 17574 17886 D SurfaceControl: Excessive delay in setPowerMode() 07-27 09:26:22.421 17574 17599 I PowerManagerService: ...