Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
230 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
121 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
341 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
101 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
139 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
39 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
276 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
456 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
2answers
100 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
94 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
120 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
40 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
325 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
71 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 (...
2
votes
2answers
991 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.)?
-1
votes
1answer
77 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-...
3
votes
7answers
571 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
vote
1answer
37 views

Search and replace substring with an other in all the files of a folder and all its subfolders

I know there are several questions as this one, but mine is specific: I want to replace the substring: localhost:8000/ with https://www.begueradj.com/ in all the HTML files existing in a folder and ...
2
votes
2answers
963 views

Replacing backslashes with forward slash within double quotes

I have some C source code which was originally developed on Windows. Now I want to work on it in Linux. There are tons of include directives that should be changed to Linux format, e.g: #include "..\...
1
vote
0answers
37 views

Replacing variables in files with value from another file [duplicate]

I have an input file which contains variable and their values. $ cat input.txt var1=SomethingNew var2=SecondPrhase classpath=/this/is/some/path I have another directory in which there are multiple ...
0
votes
1answer
63 views

DataPipeline - Repeated replace that has issues with sed (as explained) and needs to write files to new location

I need to perform a global (repeated) replace operation on the text of files recursively in a directory, but there are a few constraints that have given me issues: I need to replace in a way that ...
1
vote
3answers
63 views

sed pattern search before multi-line appending/replacement

I have a list of servers and services running on them and would wish to append the servername as a prefix to the following services Consider the following input "SERVER": "us-east-1e-421" "SERVICES....
1
vote
2answers
95 views

Switch laptop disk drive without reinstalling Linux?

I have Lubuntu 17.04 installed on my laptop's HDD. I've now bought an SSD, of almost the same size, as a replacement; it's empty, untouched. Now, I want to switch the disks and have basically the ...
4
votes
3answers
704 views

Ignore part of the string with sed

so, I have files with text formatted like this: untranslatedString : "translated string", and I need to replace characters in "translated string" part with their Cyrillic representation. I use ...
0
votes
2answers
421 views

Find and Replace Colours in CSS Files from Command Line

I have a load of CSS files in a folder and I want to be able to find and replace different values in all of these files in one go from the command line. So, for example, if I wanted to replace colour ...
3
votes
1answer
2k views

Replace multiple strings with different set of mapped strings [duplicate]

I want to replace multiple string patterns with a different set of predefined strings. For example: Input: This sentence will be converted to something different. This sentence can contain same ...
0
votes
1answer
112 views

How to make “incremental” replace in files with bash

I need to search files in directory with specific pattern (for example foobar) and replace them with foobarXXX, where XXX is a number. For example, there were two original file snt130.txt My ...
2
votes
4answers
2k views

vim regex search and replace

I'm trying to replace part of a string in a file For example I have a csv file. r1,col1,col2,35,000,col4,col5 r2,col1,col2,1,000,col4,col5 r3,col1,col2,325.33,col4,col5 r4,col1,col2,4,325.33,col4,...
3
votes
2answers
1k views

How to replace multiple lines with “sed” and convert to JSON?

{ "auth": 'log', "appid": 21, "custid": "599c1f910f53ada8468b4567", "hwid": "59e719ba0f53adfd6a8b4597" } 24/10/2017 12:44:24 -------------------------------------------------------------------...
6
votes
1answer
959 views

A posix-compliant function for replace text with parameters and regex

I'm making a function with a replacement of strings using regular expressions in a secure way, without possibility to inject characters, and without renouncing the use of regular expressions: #! /bin/...
0
votes
2answers
24 views

How to remove erroneous double quote in front of a string

cat group.txt ""BASEBALL" Flags: E,3 "Jason" "O" "Kim" "T" "Eric" "G" "Jenny" "B" "TENNIS" "Smith" "O" "Turner" "T" ""SOCCER" Flags: ...
1
vote
4answers
97 views

Script to replace last slash in the mount point

I'm trying to do a script to delete the last "/" in the mount point inside of the fstab. I create this shell script, but, I'm not happy with the result. I wonder if anyone knows how to replace with ...
0
votes
5answers
1k views

how to change last value (ip address) with sed

I read the current ip address with following command line. after then i need to replace the last value with 0/24 For example. The current ip ist 192.168.178.1 and i need to replace the var value in ...
0
votes
2answers
759 views

sed replace pattern with newline character

I'm trying to replace a specific "AllowOverride None" to "AllowOverride All" in the httpd.conf file. Given the file has multiple line with the same pattern I thought I would do a multiline pattern to ...
-2
votes
1answer
566 views

Replace a string with sentence containing multiple newline characters [duplicate]

I am trying to replace string with a sentence or paragraph contacting multiple newline characters using shell script. Replacement string will be generated run-time. eg: sed /string_to_be_replaced/...
0
votes
3answers
536 views

How to replace last occurence of a character?

I have a file composed by lines like these ones: 199240050;0180209199240050;0 199240241;0180209199240241;0 199240207;0180209199240207;0 199240400;0180209199240400;0 I should replace last number ...
0
votes
1answer
106 views

Replace a value in URL

I'm new to Linux world and need some help. I have two files : A token.txt file with a string something like this: xd2111Vf124FfmrfJ22fag And a playlist.m3u file with the following: EXTM3U EXTINF:-1,...
1
vote
1answer
404 views

find and replace macro in libreoffice

How can I write a find and replace macro to merge many items in few, as "USA, Mexico, Canada, Honduras" in "America", "China, India, Vietnam" in "Asia" and so. Before macro: USA, Mexico, Canada, ...
0
votes
1answer
191 views

Running several sed commands on same files simultaneously

To change all occurences of the string foo to bar in all files in a directory I use sed -i -- 's/foo/bar/g' * Found that here But I also want to change NAME to name etc. I tried, sed -i -- 's/foo/...
2
votes
3answers
59 views

Unix search and remove variable (contains slash) from a file

I have a requirement to search for a variable "nt" ( contains a slash). From a file text1 and remove all lines containing it $ echo $nt /u01/app/us1fa01_0/ $ cat text1 /u01/app/fa01/ /u01/app/...
1
vote
0answers
25 views

Unix replace all lines in a file starting with a string,by a variable [duplicate]

I have a requirement to replace all the lines in a file that start with a certain string to be replaced by a variable. Contents of te file - SDI=/u05/rdbms/admin NONSDI=/u07/rdbms/admin1 ...
0
votes
3answers
851 views

Replace forward slash “/” in a file

I'm using vi editor, I have a data like this in a file. 05/08/2017,U,01,116326001 05/08/2017,U,01,116226001 05/08/2017,U,01,116726323 05/08/2017,U,01,116236001 I want to replace the date(1st ...
2
votes
3answers
3k views

Replace a string in a CSV file column with another string with a single quote

I would like to replace the contents of the 3rd column of a .CSV file (using awk) by looking for a specific string and replace with another string that has a single quote and copies the output of that ...
0
votes
1answer
42 views

How do I extract a portion of an SQL statement for the purposes of searching and replacing?

I'm using bash shell attempting to do a search and replace. I have a file of lines that look like ... INSERT INTO currency (name, code, symbol) VALUES ('Baht', 'THB', '฿'); ... and I want to ...
11
votes
6answers
2k views

In `sed` how can I put one “&” between characters in a string?

Can sed make something like : 12345 become : 1&2&3&4&5 ?
1
vote
3answers
2k views

How to replace empty cells of a specific column

I have a file with many columns and some empty cells in different columns. I would like to replace the empty cells for NA only in the third column. My file: 1 id1 info 2 otherinfo 3 id2 4 ...
0
votes
1answer
4k views

Replacing a Part of URL String in a Linux File With Another String

I have an HTML file on a Linux server that contains a long list of links. I am trying to edit this file as follows. Find original occurrences of this type: http://www.test.org/name Replace them with: ...
1
vote
3answers
155 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 "...