Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [replace]

The tag has no usage guidance.

7
votes
1answer
281 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
26 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
181 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
28 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
102 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
32 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
162 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
214 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
24 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
96 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
76 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
66 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
42 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
44 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
677 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
190 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
27 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
124 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
267 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
36 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
178 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
58 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
51 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
258 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
97 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
33 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
209 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
52 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
37 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
333 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
153 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: ...
0
votes
1answer
198 views

regex to replace a word in a block in a file?

If I have: <Directory /> words allow bus </Directory> Is there a regex that can replace allow with something else and keep the other words and the block intact? So it should look ...
2
votes
3answers
97 views

How can I replace the space character in SVN dump branches name?

I'd like to replace the space () character(s) in the name of the branches with an underscore (_). For example, say I have a sedtest file containing: Node-path: trunk/ Node-path: trunk/src/lib 0 Node-...
1
vote
4answers
220 views

Removing part of all file name in a folder?

My camera stores photos in the following format: DSC_0001 (2015_07_30 10_34_56 UTC).NEF With the number after DSC_ iterating, and the brackets specifying the time and date, however all the time and ...
1
vote
4answers
91 views

Replace text with values

I have two files that need to be merged into one. File 1 example: gene_1 578 gene_2 565 gene_3 3 gene_4 77 gene_5 8 gene_6 0 gene_7 45 gene_8 67 gene_9 0 gene_10 65 File2 example: COG0430 ...
1
vote
1answer
80 views

How to Replace a string by another in a text file

I would like to replace a given string in a text file into by another, but with one extra detail. Example: If the file content's is : Library Hello1 =============== any text here version: 0.1 ------...
0
votes
3answers
119 views

Can I use sed/awk/etc to replace parts of a file with text from stdin?

I have a configuration script which does basically this: #!/bin/bash source vars.sh cat >foo.output <<EOF # some static stuff (many lines...) variable_bit=($SOME_VAR, $SOME_OTHER_VAR, ...) ...
1
vote
3answers
34 views

replacing a part of row name by sample name

I have multiple samples named p1_500sc.fasta, p2_500sc.fasta... Each file loks like this: >NODE_60_length_504_cov_1.580902 TATATCGCCGTAGATAGACGAATACGGGATTTTGAAATGACTGATATATTCAAGCACATC ...
3
votes
1answer
185 views

Joining all matches of a group in VIM

I'm trying to write a replacement command that would search for a text containing at least 4 letters separated by spaces and remove the spaces: %s/\v%(([a-zA-Z])\s){3,}([a-zA-Z])/\1\2/gc But L i g ...
1
vote
1answer
389 views

Replace a binary block within a large file

I have a partition image that contains a 1MB file populated with random data, and I would like to replace the contents of that file with another 1MB file populated with different random data. I have ...
0
votes
0answers
26 views

How to replace a serial of matrixes in a specific file, and output the these files named by different names (with the parameters) in Linux?

This is a complex question, I want to write a workflow or pipeline to draw parameters from priors parameters (M,B,D), then use these three parameters to generate 30 matrixes (20*20). I have written ...
0
votes
2answers
89 views

text file search yyyy/mm/dd and replace with yyyy-mm-dd

I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file. e.g. from this: <tag k='start_date'...
1
vote
1answer
89 views

sed command to replace a word from one file with entire line of another file [closed]

I want to use the sed command (or something that works) to replace a word in a template file with a word in a line of another file. As an example I have a file with a list of words, each word is in ...
0
votes
0answers
110 views

Why sed s acting differently on RedHat vs Mobaxterm using regexp?

I have a .txt file which includes "junk" characters, emojis. Example: 12/11/2015, 12:07 - 5465464: Super Wakkka👏🏻 12/11/2015, 12:30 - 89415: qwertz svima, nadam se 😊 12/11/2015, 12:34 - 55698742: ...
1
vote
1answer
38 views

Replace literal space with regex space

I want to change a string from This is a string to This\sis\sa\sstring but tr is not working for me no matter if I escape the \ or not string="This is a string" regex=$(echo "$string" | tr " " "\\...
0
votes
3answers
192 views

Fast string replace in recursive directories

How can I do a fast text replace with recursive directories and filenames with spaces and single quotes? Preferably using standard UNIX tools, or alternatively a well-known package. Using find is ...
1
vote
2answers
68 views

Find and Replace Duplicates

I have a file with concatenated emails in it that looks like the following: id emails 1 jeff@email.com 2 larry@email.com 3 jprice@email.com,jeff@email.com,jeff@stacko.com Each row only has ...
0
votes
1answer
27 views

Replacing different files from different folders

He everybody, I couldn't find an answer to my question, so here goes: I want to make a "job" that replaces / distributes 10000+ PDF-files from 1 directory to a unique folder where "the same" PDF (...