Questions tagged [replace]
The replace tag has no usage guidance.
418
questions
-2
votes
2
answers
70
views
awk bring same field value from file1 and set in file2 [closed]
File1 (parent)
2210 1110 Earth
2211 1111 Marse
2212 1112 Saturn
2213 1113 Pluto
File2 (child)
3310 2210 Earth
3311 2210 Space
3312 2211 Mars
3313 2211 Space
3314 2212 Saturn
3315 2212 Space
3316 ...
0
votes
3
answers
84
views
awk print only modified lines
I have file like this
d1000 1000
d1001 100
d1002 10
d1003 1
I want to modify second column where length is not equal 4.
But I want to print only lines that are modified, so original text in column 2 ...
12
votes
8
answers
2k
views
How can I replace a character within a specific context in each line of the whole file?
I have a large file which contains hundreds of English phrases in the following form:
\phrase
{. . . * * }
{I shoul-d've stayed home.}
{aɪ ʃʊd‿əv ˈsteɪd ˈhoʊm.} <- only replace on ...
0
votes
0
answers
19
views
awk or sed - find and replace in multiple files according to a key [duplicate]
I have hundreds of files in which I need to make various replacements - and those replacements are not the same in all of the files. For example, I want to replace:
WinEventLog with Windows
SysMon ...
0
votes
0
answers
29
views
How to replace text in file - conditions and arithmetic required
I need a script to change content in some text files. This a bit beyond my limited bash skills. Maybe perl or python would be a better approach, I have no experience with either of these.
I have a ...
-1
votes
1
answer
44
views
Search & replace for a string separated by whitespace upon substring match found
Below is a sample file content:
cat sample.txt
-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler....
0
votes
2
answers
53
views
sed and awk in sh script not replacing text
The desired work to find a string, and replace to another (all occurrencies), and rewrite/update the file too.
The file is an pbxproj file. I linked a sample of this file
sample of the file (please ...
0
votes
5
answers
97
views
Replace hyphen(s) with underscore(s) within angle brackets in a file
I’m aware of how to replace string;
e.g., replace hyphen with underscore in a file.
However, I wish to replace all hyphens with underscore
for all text that falls within angle brackets in a given file....
0
votes
3
answers
77
views
Search and Remove Lines of Code from all files
I need help and need to search for and remove a 3 line bit of code from all files in a directory.
Code is:
if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) )...
2
votes
3
answers
221
views
Replace dynamic word using sed command
I have a requirement where we need to replace a word in a file which can be different everytime I execute the script, the content of the file is
class DynamicContentToReplace > Something
Here I ...
1
vote
2
answers
67
views
sed replacing a string with itself and a new line
I have the following string multiple times in a html file
<br> <h4 id=...
Now, I know sed might not be perfect for html editing, but could tell me how can I replace br> <h4 id with br&...
3
votes
2
answers
218
views
How to substitute non printable characters with space character in a file
I have read nearly every answer about this topic on this website or Stackoverflow but didn't manage to solve the issue below.
When I copy the text from a PDF file and paste it into a text file file....
1
vote
3
answers
151
views
Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String?
Is it possible to Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String? It is possible that the string may contain any decimal value, which needs to be ...
0
votes
0
answers
40
views
Command: replace 'string1' 'string2' -- file
I have been using the replace command replace 'string1' 'string2' -- file in my workplace, but I forgot what the package/module have to be installed to use this command. Anyone have any idea about the ...
0
votes
1
answer
116
views
Ansible - replace first occurrence of certain expression in file - path includes hostname
I need to replace the first occurrence of a certain string in a specific file.
I think about to use the replace module of Ansible for this.
- hosts: abc
tasks:
- name: Replace first occurence of ...
0
votes
1
answer
49
views
How can I replace a word with another word in a whole hierarchy of files
I have a hierarchy of files and two words: word1 and word2.
In this hierarchy of files, some of them can contain word1. I want to replace every occurrence of word1 with word2. It is possible using a ...
-1
votes
1
answer
46
views
How to search and replace text in files but keep/reuse a certain part of text?
I want to refactor many JavaScript files in many directories which contain access to an object in this format: myObj.something.somethingElse and I want it to be myObj.getSomething(somethingElse) how ...
2
votes
3
answers
417
views
find and sed to replace special characters
I'm looking for an easy way to rename many files on my Synology NAS. find and sed are available, but not rename.
I can get a list of these files and folders with
find . \( -type d -name "@*" ...
-1
votes
2
answers
40
views
Search and replacing a string on specific file extensions with the folder name
I want to find a string ("AAA") in an specific file extension ("*.txt") inside a directory tree (../MyParentFolder), and replace it with the subfolder name (MySubfolder). I know a ...
2
votes
1
answer
176
views
How to add closing XML tags with sed
I have the following example in the XML doc:
<meta name=Originator content="text/html; charset=iso-8859-6">
<meta name=ProgId content=Word.Document>
<meta name=Generator ...
0
votes
1
answer
32
views
Searching in one file and replacing it in another file
I am searching a substring in one file and replacing it with every occurrence of word "PASSWORD" in another file. Let say I have file1 with content:
{
"outcome" => "...
1
vote
2
answers
553
views
Alternative to sed -i that does not write temporary files
I have several scripts that edit template text files, by removing a "tag" and replacing it with e.g. a number. To do this I use the
sed -i
command. However, I have an issue with write/read ...
0
votes
2
answers
57
views
Replace specified strings in file with strings from other file with sed [duplicate]
I have two files like this.
file1
line 1
line 2
... (more lines)
aaa PLACEHOLDER bbb ccc
... (more lines)
ddd PLACEHOLDER eee fff
... (more lines)
etc
file2
NEWTEXT1
NEWTEXT2
... (more lines)
There ...
-1
votes
4
answers
110
views
How to replace a part of the word using sed command
I have a file with just one word in each line. I want to delete some part of the word in each line. How can I delete that part using sed command?
Ex:
u_fox/u_snake/u_snail/u_plus/u_core/u_vector/...
0
votes
1
answer
158
views
VIM Search and Replace to Correct Broken Line Breaks
I have a file that I am busy trying to correct that has some dodgy Line Breaks inside of it, this is a small example
Row ('Row 01') Property ('Property 01')
Row ('Row 02') Property ('Property
02')
Row ...
-1
votes
1
answer
39
views
I want to replace a specific word in a text file and save the results in multiple text files using perl or ubuntu command?
I have a file results.txt that contains the following:
the word: word1 is a not detected
And I have a txt file contain the list of words as following:
word1 word2 word3 ...
And I want to generate ...
1
vote
2
answers
89
views
Complicated search and replace in Vim or Sed
I have the following (yanked from my register to retain formatting, as it's probably the reason I'm here):
<li><span>Concrete Patching (</span><span
style="overflow: ...
0
votes
2
answers
49
views
how to use sed to replace a string of characters in quotes
I want to use sed to replace the current time in the code below
time0=$(date '+%Y-%m-%d')
time1=$(date '+%H:%M:%S')
time=$(echo ""$time0"T"$time1"Z")
replace $time on ...
1
vote
2
answers
348
views
Problem trying to replace Ubuntu with Mint
I have tried replacing Ubuntu with Linux Mint. I made a file (installed.list) using apt list --installed > installed.list. It created a file with the installed packages. After that, I installed ...
1
vote
1
answer
241
views
AIX - Using Sed To Replace A String In A File
On RHEL, I am able to utilize the sed -i command to replace a string within a file, however, on AIX, it seems like the same -i parameter cannot be used.
I have a file called abc.xml that contains the ...
-1
votes
2
answers
91
views
Bash, match string and then replace everything after character in next line
What I am looking to do is find a match and then replace everything after character in the next line.
Example file contents:
super_service:
app_version: 1.02
duper_service:
app_version: 4....
0
votes
2
answers
1k
views
Struggling using sed command with variables
So I have the following variables defined in a bash script:
new_commit="back:h3912kk"
old_commit="back:1.0.1"
file = docker-compose.yml
Then I have this yml $file:
version: '...
0
votes
2
answers
123
views
How do I replace a certain pattern in multiple files?
My goal to update version number in multiple XML file like following
<?xml version="1.0" encoding="UTF-8"?>
<Component xmlns="http://soap.sforce.com/2006/04/metadata&...
2
votes
2
answers
4k
views
Using jq, how to replace the value of particular key?
How to replace the xxx with yyy?
{
"spec": {
"template": {
"spec": {
"containers": [{
"args&...
0
votes
3
answers
86
views
Replace specific lines of a file with values of other file
I would like to replace the 2nd, 6th, and 7th rows of file1 with the values in each row of file2 and generate a series of files equal to wc -l file2
cat file1
w
3
y
G
7
1.2
Q
cat file2
1 1 ...
0
votes
1
answer
161
views
If a sum equals zero how can I get awk to print another known value to the file
I have a numerous files in which I extract the total number of records and total number of missing files in order to compute data averages. I have numerous files where the number of missing records ...
2
votes
2
answers
223
views
Vendor from MAC address (first three parts)
How you can get the first three parts from MAC address?
$ mac=11:22:33:44:55:66
$ vendor=${${mac//:/}:0:6}
bash: ${${mac//:/}:0:6}: bad substitution
${mac//:/} removes : and :0:6 should get the first ...
-1
votes
4
answers
60
views
Help with SED to replace
I want to replace
C:\Documents and Settings\sjohnson4\AppData\Local\Microsoft\Teams\current\Squirrel.exe
with
C:\Documents and Settings\USERNAME\AppData\Local\Microsoft\Teams\current\Squirrel.exe.
...
-1
votes
5
answers
140
views
Replace characters on specific lines and specific columns
Consider this sample.txt:
ATO N X B
AT H1 X BT
ATOM H25 X BAA
ATOM H3 X BUTZ
ATOM CA X BAT
I want to replace X's from lines 2-4, ...
0
votes
1
answer
45
views
replace string from left to right in a line
I want to search and replace the negative values with the value just before it. The values are separated by comma.
Example:
ocv_sigma_cell_rise(table_7) {
sigma_type : early_and_late;
values(&...
0
votes
3
answers
351
views
find text in one file and replace with text from another file SED or AWK
Ubuntu 18 build
I am trying to find this text, [define( 'AUTH_KEY',] without [] in /var/www/file1.txt, and then copy the line and replace the same line in /var/www/file2.php. I have tried multiple ...
0
votes
0
answers
52
views
replace remove command (in Linux - overall) with shred
short question: as the title suggests, a system-wide shred instead of the command rm
Long question:
I know about the "replace" command,
as well as I could just to rm = shred (or something on ...
-1
votes
1
answer
43
views
Find a pattern and replace everything following that pattern with another pattern
I have data like this:
1_filename=$MYPATH/abcd/your_path/img.bin
2_filename=$MYPATH/cdef/jdskjdk/img2.bin
1_filesize=10mb
2_filesize=12mb
My expected output is:
1_filename=img.bin
2_filename=img2....
1
vote
2
answers
226
views
Replace several consecutive lines with a single line using sed
In all my python scripts, I'd like to replace the 2 consecutive lines
import matplotlib as mpl
mpl.style.use(mpl_plt_default_template)
with just the line
plt.style.use(mpl_plt_default_template)
So ...
0
votes
1
answer
125
views
Replace "),(" with "),\n(" in Linux
Hy everybody.
I have the following insert in a MySQL script file as an example that I obtained from mysqldump in Linux Ubuntu Server with no GUI.
INSERT INTO `table` VALUES (AAAA, BBBB, CCCC),(DDDD, ...
-1
votes
2
answers
92
views
replace a particular text after N-th occurrence of a character
I want to replace the numbers in below file with #Mi.
Only for numbers after the 10th occurrence of " (double quote)
Input File
"col1" "col2" "col3" "col4" ...
0
votes
1
answer
404
views
Replace strings in a big text file based on fields from a CSV file
I have a big text file (roughly 2GB). I have a csv file that has the following fields:
rowID,pattern,other
1,abc_1z1,90
2,abc_1z2,90
3,abc_1z10,80
4,abc_3p1,77
...
My interest is: replace the content ...
-1
votes
3
answers
75
views
replace all occurences of colon and values around it for a tab [closed]
Thanks for the help.
I have done this:
cat file1.txt | sed 's/1:2=//'| sed 's/1:3=//'| sed 's/1:4=//'| sed 's/1:5=//'| sed 's/1:6=//'| sed 's/2:3=//'| sed 's/2:4=//'| sed 's/2:5=//'| sed 's/2:6=//'| ...
1
vote
2
answers
66
views
Perl pattern match and substitute to replace only 4th word and retain everything else
I need to replace the 4th word on every line with 0:
Original:
R5_427 MMP15@2:S VDD:1 967.796 TC1=0.0004785156
R5_428 MMP15@2:S lninst_M55:S 0.001
Expected output:
R5_427 MMP15@2:S VDD:1 0 TC1=0....
1
vote
1
answer
83
views
How to replace text between quotation marks with something from another file?
I have the following kind of text:
$OU = 'or';
$DINHEIRO_CAIXA = 'Cash balance';
$PAGINA = 'Page';
$DE = 'from';
$ENVIAR = 'Send';
$PRINCIPAL = 'Main';
I've already got all the text within the single ...