The replace tag has no usage guidance.
7
votes
5answers
417 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 ...
2
votes
2answers
36 views
Replace string in multiple files using find and sed
So I've arrived at the conclusion that for recursively replacing all instances of a string in directory (only for .java extensions files) I need to use
find . -type f -name "*.java" -exec sed -i 's/...
2
votes
1answer
68 views
Remove white spaces before certain characters
I am trying to remove spaces from text like:
Ala ma kota ,psa i kanarka
, chyba . . .
in order to get
Ala ma kota,psa i kanarka, chyba...
I was trying with sed command:
echo $'Ala ma kota ,psa i ...
0
votes
0answers
28 views
Replacement of strings using regex with sed
I am trying to replace this:
mysqli_query($query_tpl2,$linkid_log);
with:
mysqli_query($linkid_log,$query_tpl2);
where query can be anything (any word, that is).
I have this seemingly working reg ...
0
votes
2answers
27 views
Replacing string with other string
In line((s) that originate from csv file)
14/Feb/2016:15:21:33-0500]http://map1.link.de/mk
what is the easiest part to replace/delete&add
]http://map1.link.de/
with
,
having in mind that ...
0
votes
1answer
34 views
sed replace first occurrence of “space-tab” pattern
I have some troubles removing the string between the first space \s and the first tab \t of a text file (the tab should be kept):
sample input:
col1_frame1 unimportant a b c
expected output ...
0
votes
0answers
26 views
Add the set of commands at the beginning of multiple files
I need help in writing a code for replacing a part of file with other. I am handling hundreds of files so it will be of great help for me if someone could help me in making this automation. I have ...
1
vote
2answers
34 views
Sed error replacing partial string with variable [duplicate]
I have 3 text files. I want to search file3 for a string in file2 and replace it with a string in file1 in found. I need to append a custom tag from file1 to the end of the string in file3, replacing ...
1
vote
1answer
69 views
Find and Replace of All Names
Background
I am new to linux/unix (I'm on a mac. Don't know which I am using), but someone made a lot of folders and files under the wrong name, and I need to go in and replace everything with the ...
0
votes
1answer
15 views
Change last character in found sequences
I want to change every first / in side \ukindex into !.
E.g. \ukindex{duality/weak|)}% becomes \ukindex{duality!weak|)}%.
I can find all such occurrences with grep linear-programming.tex -e '\...
1
vote
1answer
39 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 ...
3
votes
2answers
154 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 ...
4
votes
1answer
469 views
using sed with ampersand (&)
I'm using sed to find and replace patterns within SAS files I have rather than changing them individually. The problem is I am trying to replace macro variables and when I use the ampersand it is not ...
1
vote
2answers
74 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 ...
0
votes
2answers
95 views
Remove injected code from all php files in directory on Ubuntu [duplicate]
I have a site where some code was injected into a very large number of php files and removing them manually is not feasible due to the number of files.
I can search for a variable name from the ...
0
votes
3answers
71 views
Vim Search and Replace - Regex
I want to perform a search and replace. A newline before any non-digit should be replaced with tab. I tried
%s/\n\D/\t/g
but it replaced the first character of the word following the newline, which ...
2
votes
1answer
216 views
How can i replace multi line string using sed? [closed]
I have tried the following command:-
[root@10 bin]# cat temp
asdjahskjdhajksdhjkashjahfksjdhfkjsddhflkdsjhfklsdajhfklajshdkjalsdlkjasdhkljas
hskdajkdhkjas
cast $recv $UE_CAPABILITY_ENQUIRY
...
1
vote
1answer
58 views
Replacing variable containing \ with sed
i am trying to replace $old string with $new string in file where:
old=ESX_10.1.1.1\@11.11.11.11
new=host_15_11_0_111.static
I am using sed command:
sed i "s/${old}/${new}/g" /filename
but it ...
0
votes
1answer
32 views
Performing Prime Key function using 'Sed' in Bash
I am using bash and trying to employ sed command for matching a string and replace it with another between two files.
Objective:
To replace all strings[sp_*] by matching them from another file ...
0
votes
2answers
76 views
Delete rows from postgres database contain string/sentence [closed]
I would like to know how to delete entire rows in a postgres table that contain a particular string in the title column. So if the string is:
it is a sunny day
How can I issue a command in postgres ...
0
votes
1answer
158 views
Using regexp_replace to replace single quotes around string but not within words e.g. can't
I'm using the below code from a bash script to replace single quotes from my title column in a postgres database with spaces.
psql -U postgres -d my_database -c "UPDATE my_table SET title = ...
1
vote
1answer
36 views
changing a specific 'column' inside a txt file
I have a file with thousands of entries like this:
6/05/2016,32,34,40,45,48,,01,10
10/05/2016,02,26,27,40,49,,05,10
13/05/2016,07,15,28,31,42,,10,11
17/05/2016,15,27,32,36,39,,03,10
I want to ...
0
votes
1answer
191 views
how to find and delete certain regex in geany text editor?
I have a sample text like this:
\documentclass[a4paper]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{color}
\setlength{\...
1
vote
1answer
81 views
Replacing mysql settings with sed
I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...) lines in db.txt.
I have ...
2
votes
5answers
181 views
Replacement of XML based on attribute content using sed
I've got to replace some attribute content in an XML tag, depending on a parameter $1.
We've got in input, for example:
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="OO ...
2
votes
1answer
60 views
sed - Use file1 to find replacements contained in file2 for lines from file3 [duplicate]
I'm new here and haven't posted much, I'll try to make this as clear as I can.
I want to perform a find and replace that involves three files: find.csv identifies lines containing strings. I want to ...
-2
votes
1answer
54 views
How to replace all dots in vi
How to replace in vi? There are numerous explanations in Internet, but most of them doesn't contain information about which buttons to press.
If I enter
:s/[.]/[.] <ENTER>
then only one ...
0
votes
2answers
50 views
Sed replace not functioning as expected
I want to replace listen = 127.0.0.1:9000 by listen = '/var/run/php56-fpm.sock'
sudo sed -i 's/listen = 127.0.0.1:9000/listen = \'/var/run/php56-fpm.sock\'/g' /etc/php-fpm.d/www.conf
Error:
bash: -...
1
vote
2answers
94 views
Bash find and replace in a C++ file
I have a C++ script for which I would like to change variable values in some places and then compile, doing this many times for a set of numbers. The following shows my shell script:
#!/bin/bash
...
3
votes
2answers
189 views
How to replace a piece of text only if it doesn't appear elsewhere in the file?
Suppose I have some text like this (output of objdump -d):
0: 0f a2 cpuid
2: a9 01 00 00 00 test eax,0x1
7: 74 01 je a <myFunc+...
-3
votes
1answer
103 views
How do i create a sed script to prompt the user to replace a number in a file? [duplicate]
I'm new in Unix, and I'm learning about sed command. I need to write a very small script for searching a number in a file and replacing it. I tried doing grep, and than deleting the specific phone ...
3
votes
2answers
111 views
Replace only in particular range string
In the canonical How can I replace a string in a file(s)? in 3. Replace only if the string is found in a certain context, I'm trying to implement the replace of a pipe with white spaces in file with ...
1
vote
2answers
59 views
SED Search and Replace on Linux [duplicate]
I want to change the value from 1521 to 1525 in FROM_HOST only in file gexhosts.cat:
FROM_HOST db201521
TO_HOST db201521
Is there a way to do that or some work around?
I would really prefer ...
0
votes
0answers
9 views
how to replace a string in vcf file which have a common charecter? [duplicate]
I want to replace any string which have the common charecter. like any string which have 1/1 in it will be completely replaced by "heteroV!"
I have tried this command
sed -iBAK2 's_\(1/1:[0-9]\+:[0-...
-1
votes
1answer
75 views
how to find and replace a string containing “/” [duplicate]
I am very new to linux. currently I have faced a problem in changing a string in a file which have / character . I want to replace 1/0 with hetero in a file. can you please tell me which command to ...
-3
votes
2answers
105 views
Find and replace in Linux [closed]
I want to replace 0/1 with hetero but whenever I am trying to use the known commands it is showing syntax error because the / is aleady part of the command .. Can anyone suggest a command to solve ...
0
votes
1answer
57 views
Deleting multiple lines of HTML comment using sed
This is what I came up with but it doesn't work with multiple lines:
sed -i '/<!-- my comment -->.*<!-- \/my comment end -->/d' my_file
2
votes
3answers
1k 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 ...
1
vote
1answer
36 views
How to replace a word in a file by a word get by read function? [duplicate]
Situation:
echo "tell me a word"
read the_word
How to replace all WordToReplace in a file by the_word?
sed does not seems to appreciate:
sed -i 's/WordToReplace/$the_word/g' thefile.sh
0
votes
4answers
226 views
How do I remove all \r\n from a file, but preserve \n
I have a CSV with unix line endings, but some of the string values have windows line endings in them:
date,notes\n
2014-01-01,"Blah Blah Blah"\n
2014-01-02,"Two things:\r\n - first thing\r\n - ...
0
votes
2answers
73 views
If filename has more than n characters, delete the last ones
I'm kinda new with the unix shell, and I don't seem to find the answer of my problem :
I have a folder containing multiple files : a correct filename contains exactly 13 characters (numbers + letters ...
0
votes
3answers
208 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
...
0
votes
2answers
60 views
sed to change dns log string format
I want to use sed to change the following text:
(3)www(5)first(3)nth(6)domain(3)com(0)
to:
www.first.nth.domain.com
Can each group between the parenthesis separators be captured and then ...
0
votes
0answers
18 views
replace values in columns by comparing [duplicate]
I need help, i have two very large space-delim files,
File 1.
527858 2 2 27.92464882 8.63E-07
570289 4 2 30.12532071 2.87E-07
571034 1 2 29.26089611 4.43E-07
571033 5 2 28.56723908 ...
1
vote
4answers
265 views
Bash command help to “search and replace” file in changing directory tree
The Scenario:
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 ...
1
vote
1answer
68 views
Recover files inside a folder which was replaced by an empty one. (openSUSE, Ext4)
Is there a way to restore a folder or better the containing files and folders of the folder which was replaced by a empty one with the same name?
FileSystem: Ext4
OS: openSUSE 42.1
If it is ...
0
votes
1answer
42 views
How to replace word in specific column if it does not match an expression?
I have the following file:
chr1 157784 157887 U6 0 -
chr1 564813 564881 miRNA 0 +
chr1 564879 564950 tRNA 0 -
chr1 564952 565019 tRNA 0 +
chr1 566062 566129 ...
1
vote
1answer
47 views
Escape >');} < / in sed
In 30 files in 30 directories, I want to find:
script>');} < /script>
and replace it with:
script>');} < /script-->
What special characters do I need to escape in the find field?
...
0
votes
1answer
103 views
replace long text string (script with MANY special characters). sed, awk, grep
My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
1
vote
2answers
105 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 ...