Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
30 views

Replacing comma if found inside double quotations in a CSV file using sed

I have a CSV file which I need to load to a MySQL table. I rely of identifying the columns end by the , character. That's why it is important that the , does not appear elsewhere other than as a ...
-1
votes
0answers
17 views

salt.state.file.replace: replacing entries in /etc/fstab

I would like to achieve the same as under sed: replacing entries in the /etc/fstab, but as salt.state. How would you implement the following awk-command as salt.state.file.replace? awk '$2 ~ "/tmp"{ ...
0
votes
1answer
28 views

How to replace multiple file lines with an edited grep output?

I grep recursively in a directory, now I got an output. Look through the lines, I change lines what I need to change, and remove lines what I don't need to change. like grep.txt ./path/a.c:12345: ...
0
votes
1answer
50 views

Replacing the word(case senstitive) in a file

I am new to linux, I have one 200 lines in a file. In that file I need to replace the specific word eg: existing word: foo New word : bar I read some blogs...i understood it can be done with sed. ...
0
votes
0answers
30 views

Replace multiple lines in multiple files

I have the following section in more than 100 files that I want to replce: ] }, "value1": [ { "value2": { "task1": 0, "task2": 0, "a": 0, "b": 0, "c": 0 } }...
0
votes
2answers
67 views

sed add first word from previous line to beginning of the next line, if

I ran into a problem and can't find a solution to fix the following issue. I want to copy the first word of a line to the beginning of the following n lines if they start with a special character, ...
1
vote
3answers
39 views

VIM: scripted search and replace?

I am switching to Linux and used to have NoteTab Pro, which allowed me to do scripted search and replaces... as I need multiple replace sequences to achieve a certain outcome. I'd like to put these ...
0
votes
1answer
26 views

How to replace spaces with _ for specific lines

I have a text file with multiple paragraphs. Each paragraph has headers with spaces. I want to replace the spaces of the text found between [ and :, with _ . Here is an excerpt of the text from the ...
1
vote
1answer
25 views

Vim search and replace html tags reusing hits

I want to replace html tags in vim but reuse what I found. Namely I want to replace <div class="subSectionTitle"> Title 1 </div> with <h1> Title 1 <h1> I tried to ...
-2
votes
1answer
122 views

Data searching (matching) mechanisms standard in generally all Linux systems [duplicate]

I feel confused about what data searching (data matching) mechanisms are standard in generally all Linux systems, as being utilizable by generally all shell builtins and additional common utilities, ...
1
vote
2answers
67 views

Replace multi line string with multi line string without escaping by hand

Say I have a text file text.txt and I want to replace a (multi-line) string that is contained in before.txt with another string that is contained in after.txt, how do I do that? (I dont want to use ...
0
votes
2answers
29 views

Change [tr][tr]{X} into [tr][tr]{\tinyX} in a long list of files within bash?

Newbie here. I am trying to program a bash script that will replace, for each file in a folder, the following sequence: [tr][tr]{X} where X is any decimal number (collection of digits and ".") with [...
1
vote
1answer
47 views

Update specific value of one file by values in another text file

I have a text files in ascii format and wanted to replace a specific value by value saved in another text file. consider a file of name text_1. . . . 50.asc 5 columns, 4 rows sample data in a file ...
1
vote
1answer
41 views

Text processing with sed on a variable in bash not giving expected (modified) output?

We are using some outdated encoded script which does not to be allowed to be modified. Therefor I though of a solution to modify the input automatically by using sed. This didn't work and after ...
0
votes
1answer
85 views

translating text in lua file

The thing is, I'm translating a game from English to Polish language. The text I'm trying to translate is in lua-files. I have most of the game translated, but I'm looking for a way to automatize ...
1
vote
2answers
38 views

replace expressions of the form \myExpr{this is a sentence} with “this is a sentence”

I'm sure this has been answered before, but I have a long file with a bunch of expressions of the form \flagThis{Flag this sentence} and I want to replace each of them with Flag this sentence. ...
0
votes
2answers
113 views

Pipe sed capture group through external program before replacing?

Is there a way for sed to pipe a capture group to another program, making \1 in the regexp's RHS equal to the output of that program? For example, running sed 's/lorem ipsum \(foobar\)/\1/g' file....
2
votes
2answers
97 views

Easiest way to get `+` indented `tree` output

I need to replace indentation in tree output with + signs so that instead of this: $ tree --noreport dir dir ├── dir1 │ ├── file1 │ └── file2 └── dir2 ├── file1 └── file2 it'd print this:...
0
votes
1answer
48 views

Sed with regular expression and fixed part

I have a file with <vcell i="2" v="2" s="0" m="0"/> <cell i="3" v="3187"/> <cell i="4" v="1"/> <cell i="5" v="17"/> <cell i="6" v="0"/> <cell i="7" v="2"/> <...
1
vote
1answer
47 views

Replace each letter in a .txt with the letter six positions later

I want to "encrypt" a .txt by replacing each letter with the letter six positions later. What I have right now is: tr [:alpha:] ??? < myfile.txt But I don't know what to put in ??? ... Any help ...
0
votes
1answer
52 views

Replace character ý to \n

I hope someone can help or point me to the right direction. I am searching very hard for 2 weeks now. Here is the thing, I am on Linux (RHEL) and I have to replace character ýto a \n from an input ...
0
votes
1answer
24 views

search and replace of users hash from old server to the new one

quite often I have to set the same password on new servers as it is on the old one, I can do it manually simple paste hash from the shadow, but I'd like to learn to do it automatically. old machine A ...
0
votes
1answer
78 views

Output remote hostname in sshpass session

I have created a shell script to connect to a list of servers using sshpass and run a list of about 30 commands. An extract of the script is below. The script will wget a new config file, but then I ...
3
votes
2answers
100 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
277 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....
0
votes
0answers
23 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 ...
0
votes
2answers
61 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
1answer
61 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-...
1
vote
1answer
33 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
58 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
35 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" ...
2
votes
3answers
73 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
76 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
1answer
103 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
41 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
55 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
99 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
27 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
31 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 '>' ...
1
vote
2answers
69 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 ...
1
vote
4answers
82 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
1k 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
103 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
100 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 ...
1
vote
3answers
386 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
39 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
35 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. ...
0
votes
3answers
66 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
67 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 ...
0
votes
2answers
229 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
2 3 4 5
8