Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
8 views

How to replace a column of numbers in a lot of filesnames

I would like to rename many files, named like this: cc cc nn - ccccccc ccc cccccccc - nnnnnn.mp3 where "c" means a character and "n" means a number cc cc nn - ccccccc ccc cccccccc - nnnnnn.mp3 ...
0
votes
4answers
31 views

Find and replace after a string after a specific character

I have the following lines in my input file and I would like to replace all the text after "=" sign with a new string, say "good". Again, I would like to do this only for certain strings in the line....
3
votes
4answers
817 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: ...
0
votes
0answers
15 views

Lenovo IdeaPad: Original keyboard dead keys, replacement randomly made keystokes then failed

Problem is too complex to fit in Subject line. First, my keyboard had some dead keys, so I replaced it with a new keyboard . The replacement keyboard started to make Enter keystrokes randomly by ...
1
vote
2answers
6k views

Save file after using sed command

I am using following command to replace yyyymmdd to YYYYMMDDHH24MISS in my file: sed -e 's/\('yyyymmdd'\)/\('YYYYMMDDHH24MISS'\)/g' filename After I run the command in PuTTY, it displays the file ...
0
votes
2answers
53 views

Placing matching occurrence number to the left side of the occurrence itself

I have a file with multiple occurrences of the expression ".mp3". I want the first occurrence to become "1.mp3", the second occurrence to become "2.mp3", and so on. It would be something like awk '/ ...
0
votes
2answers
53 views

Extracting multiple strings, according to a pattern, in a bash script

I'm writing a shell script to generate a directory listing. as an input a receive a long html string : https://www.mycompany.com/posts/aureliaflore_china-seoul-startup-activity-6571925510337728512-...
3
votes
2answers
296 views

SED challenge,aggregating String containing braces

I've been trying to use sed for aggregating a specific string pattern within a text for hours, but can't find the solution. I hope you guys know how to do it!? The text subject to my Goal consists of ...
1
vote
1answer
23 views

Vim - how to replace a space after dot with a newline?

I've pasted some text from the Web into Vim editor and for some reason each paragraph is treated as a single line: PROD $ egrep -i 'system' text Hurricane Dorian is a strong tropical cyclone ...
0
votes
1answer
45 views

Replacing the multiple values from a string with the values of file in bash

I have one sql file on which I'm doing cat and assigning to a variable say "SQL". I have different DATABASES and different TABLES in sql file. I'm trying to replace those tables and databases value ...
1
vote
1answer
27 views

Bash replace special character '

All the questions and answers i already read are not my solution. So, all i want to do is to replace the special char ' in bash. This works: A="abc" B="${A//[b]/x}" But this does not work: A="a'b" ...
84
votes
12answers
39k views

vim - how can i do a 'change word' using the current paste buffer

I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer. I now go to the word 'bar' and I want to replace it with my paste buffer. To replace the text ...
2
votes
3answers
44 views

Loop over numbered files and append on every line of file the content of another file with the same number

I have a lot of numbered *.csv files with different numbers of lines and just as many *.txt files. I want to append on every line of file 1.csv the content of file 1.txt, on every line of file 2.csv ...
2
votes
3answers
61 views

How to find the last occurrence of a string in column 1 and replace the corresponding value in column 3?

I have three columns in a file as such: apple1 10109283 20012983 apple1 10983102 10293809 apple1 10293893 2349823049 apple10 109283019 109238901 apple10 ...
3
votes
4answers
9k views

bash / sh script to replace text between some tags/strings in a text file

I am creating executable which will be executed with /bin/sh or /bin/bash script, I have a file which contains a structure like, there will be only one #start and #end tag in the config file, and I ...
3
votes
1answer
55 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
34 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
40 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
33 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
27 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 '>' ...
2
votes
3answers
131 views

Replace string 1 only when string 2, 3, or 4 present

Basically I am an oracle dba. We have a task to switch-over from primary db to standby db and we need tns entries (host-name) to be modified from sape-scan to sapi-scan in the tnsnames.ora file ...
2
votes
3answers
1k views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
1
vote
2answers
64 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 ...
10
votes
5answers
35k views

Sed : Replace pattern on every second newline?

Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to). Edit ...
1
vote
4answers
67 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
78 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
29 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
82 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
2answers
77 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 ...
1
vote
3answers
110 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
28 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
32 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. ...
1
vote
2answers
3k views

How do you search and replace multiple lines in KDE Kate?

how do you replace multiple lines of code in Kate? The following is the original text: <div id="image"> <br style="clear: left"/> <br style="clear: left"/> <br style="clear: ...
0
votes
3answers
58 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
42 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 ...
1
vote
4answers
525 views

Bash command to “search and replace” file in changing directory tree

I've built a collection of files for research in a central repository on my server. I'm continually curating the repo changing the directory's tree structure by renaming and moving directories. And I'...
7
votes
2answers
2k views

shell script/utility replace 2 byte unicode in binary file

I have many large Unicode files. I would like to replace each Unicode byte pair with a new Unicode byte pair. For example, the original file contains "C3 B9 C3 AB C3 B8 C3 B0" and I would like to ...
0
votes
3answers
385 views

replace everything and move word to end position

maybe my question should answered in two ways but I hope it could be done with in one "sed": I have the following lines, with different IDs: ID1_TRINITY_DN120587_c0_g1::TRINITY_DN120587_c0_g1_i1::...
5
votes
2answers
8k views

use awk to replace parentheses?

How can I use awk to replace the parentheses in these 2 scenarios? Change empty parens to the word "None" 192.168.0.24,Up,() Remove parens to only host.domain.com is left 192.168.0.25,Up,(host....
7
votes
1answer
304 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. ...
1
vote
3answers
807 views

How to search and replace a string with newlines on commandline in a file

I want to replace all occurrences of a text string in a textfile on command line on CentOS 7.2. Search-string: ).\nPORT Replacement-string: ). \n0 closed ports\nPORT I know, this can be achieved ...
-3
votes
1answer
64 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 ...
1
vote
2answers
460 views

replace a block of text with the contents of a file

I would like to replace the contents between $Elements$ and $EndElements$ in text file, f1, with the data from another file, f2. The contents of f1 is given simply by $Elements$ 3 1 5 7 $EndElements$...
24
votes
7answers
9k views

How to replace current word under cursor in Emacs

How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. ...
2
votes
2answers
270 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
114 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
305 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 ...
3
votes
3answers
592 views

Can I reboot during a btrfs replace and then resume it?

I have a damaged hard disk with a lot of read errors. I'm currently doing a btrfs replace, but after 24 hours at just over 5% done, this is a problem: it's my work computer; I'm currently booted onto ...