Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
2k 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
350 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
43 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 ...
1
vote
3answers
159 views

Replace characters at a specific index counted from behind

I want to change some characters in a string I create. I make a filelisting and from each file I need to append the "stat" information. For example filename "K181_111126.CATProduct" results in "...
0
votes
1answer
34 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" ...
1
vote
1answer
99 views

How to replace a symbol in sed only if it occurs before a letter?

In my documents, I have lots of occurences like these: [["A [["b [["8 [["c [["F [["1... What I need to do is to replace double brackets with single brackets, but only if there is a letter after a [["...
0
votes
2answers
523 views

Find words after specific symbol on line

I need to make a bash script that reads a file containing variable = text. What I need is for the script to check the file, ignore the variable name and search for a word in the text after the = ...
0
votes
1answer
42 views

Add the set of commands at the beginning of multipls files

I need to write a script for replacing a part of file with other. I am handling hundreds of files. I have a list of commands to be added to a bunch of text files. But in the files I have a common ...
0
votes
2answers
1k views

Replace comma delimited file with pipe, but not remove comma or quotes etc within text qualifier field, however, remove text qualifier!

My file is a comma delimited file and text qualifier is ~, but my requirement is to find and replace comma delimited file with |(pipe) delimited file and remove text qualifier ~ with nothing, however, ...
23
votes
5answers
15k views

How to report “sed” in-place changes

When using sed to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)? For instance, how can I change the command line ...
0
votes
2answers
245 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
453 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
217 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
72 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 ...
69
votes
5answers
165k views

Remove line containing certain string and the following line

I use this cat foo.txt | sed '/bar/d' to remove lines containing the string bar in the file. I would like however to remove those lines and the line directly after it. Preferably in sed, awk or ...
3
votes
3answers
772 views

How can I use (sed|awk) to mask an e-mail address with asterisks like <j******e@g***.com>

How can I mask a list of e-mail addresses like: John Doe <john.doe@gmail.com> John Doe <johndoe@hotmail.net> Jane Doe <j.doe@outlook.org> ... with sed (or awk) into something like: ...
-1
votes
2answers
119 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 ...
0
votes
3answers
106 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
3answers
267 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 ...
-2
votes
1answer
39 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
274 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
62 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
6answers
21k views

Replace all values in one column to 1

I have multiple text files containing 12 lines and 3 columns. Example: 2 6 0.74 42 6 0.58 80 6 0 112 6 0.24 132 6 1 216 6 0.7 342 6 ...
1
vote
2answers
223 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: ...
8
votes
4answers
435 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 ...
0
votes
1answer
244 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
126 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
359 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
106 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
81 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
146 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
1answer
6k views

How to replace the content of specific column with awk? Tab Delimited File

Here's a similar question but I ran into a problem that was not addressed in the question. How to replace the content of a specific column with awk? I want to do something similar, however my file is ...
1
vote
3answers
42 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
294 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
466 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 ...
28
votes
3answers
45k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
0
votes
2answers
106 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
98 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
122 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
42 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
352 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
73 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
28 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 (...
8
votes
3answers
7k views

How does one find and replace text in all open files with kate?

How does one find and replace text in all open files with kate?
2
votes
2answers
1k views

Is there a way to replace last occurrence of match using a shell variable substitution?

% x=abracadabra % echo ${x//a/o} obrocodobro Hmph... Is there a way to replace the last occurrence of a pattern using shell substitions (IOW, without rolling out sed, awk, perl, etc.)?
3
votes
7answers
582 views

Remove comma outside quotes

I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row 123,"ABC, DEV 23",345,534.202,NAME I need to ...
-1
votes
1answer
78 views

find and replace [closed]

I have 2 files. The first column (separated by ",") in file1.txt is equal in file2.txt. I want to compare both files and replace for second column in the file1.txt in file2.txt file1.txt ABC-aBc-...