Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-1
votes
2answers
49 views

Replace characters in a hapmap data set

I am thinking to use a bash code to solve the following issue in my data. Considering the bellow data set in hapmap format in which I need to replace some characters (letters in this case) based on ...
20
votes
3answers
42k views

Replace text quickly in very large file

I have 25GB text file that needs a string replaced on only a few lines. I can use sed successfully but it takes a really long time to run. sed -i 's|old text|new text|g' gigantic_file.sql Is there a ...
2
votes
2answers
438 views

Using sed (or anything useful) to replace strings with relative content

Usually to replace strings across multiple files, one simply needs to use sed -i 's/string1/string2/g' * However, how could I use the sed command (or anything that works, really) to replace things ...
4
votes
4answers
6k views

Substitute placeholders in template

Say I have a shell configuration file config like this: HOST=localhost PORT=8080 Now I have a template template like this: The host is <%= @HOST %> The port is <%= @PORT %> How do I ...
1
vote
1answer
758 views

How can I find and replace only in a range of columns?

I have a text file with 9267 lines. I want to find "A" with 5 spaces after it and replace it with "A" with 5 spaces before and after it on all lines, but only between columns 67 and 88. Text outside ...
1
vote
2answers
261 views

How to separate gene names joined by underscore?

I would like to separate gene names that were joined by dash. I would like to replace by tabs. My input file is: Cedr3g0570.1_XP_019283.1 Cedr4g7930.2_XP_019241.1 Cedr5g005170.1_C0LGS3.1 Cedr7g0290....
0
votes
1answer
3k views

SED command to replace “[Word1 Word2]” to nothing

I am looking for the sed command to replace text like this "[word1 word2]" to nothing. I tried sed -i -e 's/[Word1 Word2]//g' It didn't work and replaced entire my text in disorder way. I would ...
4
votes
3answers
908 views

how to emulate “replace a b b a” with a sed?

I am trying to emulate a replace command which swaps two characters, with a sed script, but the obvious choice: sed -e 's/a/b/g' -e 's/b/a/g' does no work. Can you point me how to do it correctly?
2
votes
0answers
178 views

History expansion in fish

I want to run the previous command with part of it replaced. In bash, I can use the history expansion feature: ^x^y runs the previous command again, except with x replaced by y. I tried it in fish and ...
2
votes
2answers
115 views

sed: excluding serveral part strings from matched pattern

So the idea is to replace matched pattern nas_... with nas_$SCL using $SCL variable in a file, but excluding 2 exact matches nas_mba && nas_tvr, which should not be replaced So far I've got ...
2
votes
6answers
1k 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 ...
3
votes
3answers
281 views

Replace content inside two specific lines

How to replace, from command-line, the content between <!-- Analytics code start --> and <!-- Analytics code end --> of index.html: <html> ... <!-- Analytics code start --> .....
-1
votes
1answer
185 views

How to search and replace in the entire system? [duplicate]

Say I have an IP address + domain (1.1.1.1/example.com) appearing in many different files which are prevalent inside different files throughout the system and I want to change it's IP to something ...
0
votes
2answers
50 views

search string in files and replace it incrementally

I have a directory with 152 files named plot_1 to plot_152. In each of those there's some R code with some index [[i]]. Using Kateversion 15.08.2, is it possible to search for [[i]] in each file and ...
2
votes
1answer
55 views

Replace parts of files

I'm quite new in the linux world. I've got a file containing Usernames and Passwords, for browser authentications. eg.: user:ioeuwz5rf (Password generated with "openssl passwd ABCXYZ") Now, I want ...
2
votes
3answers
282 views

Replace a dynamic file extension with a fixed file extension

I need to replace dynamic file extensions which contain timestamp for certain date with a fixed file extension. For example, 08242016G0040156.ZIP.20160907141452 09042016SHOC0003.ZIP....
1
vote
1answer
85 views

Read Text File; Copy Non-Indented Text Line; Replace Beginning of Indented Lines with Said Text

I have a text file I want to manipulate the text in. An example portion of the file is below. I want to read the first non-indented line and insert that text at the beginning of all the following ...
0
votes
1answer
496 views

Replacing one column with another column in csv files [duplicate]

I have a file1 with the following: 1,joe,jim,bob,sally,mark,sue,etc,etc 2,julie,barbra,joe,jim,bob,sally,mark,sue,etc,etc 1,clarie,mike,joe,jim,bob,sally,,etc,etc 2,matt,alivia,joe,jim,bob,mark,sue,...
4
votes
2answers
699 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
0
votes
1answer
731 views

Execute command in dynamic directories via shell script

My main directory is /home/hts/.hts/tvheadend/input/dvb/networks/1d38df81855dee2d39e692ecc4caf05c/muxes In there are many more directories with radomly generated names Example: /...
4
votes
2answers
11k 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/...
17
votes
1answer
16k 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 ...
2
votes
1answer
2k 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
2answers
38 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
544 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 ...
1
vote
2answers
4k 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
487 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
96 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
4answers
5k views

Replace specified character between two strings?

i have something to accomplish. i need to replace all occurrence of & inside or between <ex> </ex> to #. actual example below: a & b & c <ex> a & b & c </ex&...
3
votes
2answers
284 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 ...
6
votes
1answer
17k views

Editing a child JSON element value with jq

I'm trying to use jq in order to change a child's value. For instance, I want to change the value of "test2" from ["yo", "bye"] to ["hi"]. { "title": "hello", "body": { "test1": 123, ...
0
votes
2answers
819 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
181 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
1k 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
540 views

Replacing variable containing \ with sed [duplicate]

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 ...
10
votes
2answers
2k views

Case-preserving search and replace in vim?

In vim, I know I can search with or without case sensitivity. But if I want to search for a string in either upper or lower case, and replace it with a replacement of the same case, is that possible ...
0
votes
1answer
103 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 ...
1
vote
2answers
3k 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
3k 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
43 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 ...
1
vote
1answer
2k 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
473 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
1answer
209 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
1k 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 ...
2
votes
1answer
136 views

CentOS replace config error

I'm currently working on updating our CentOS server, however whenever I'm trying to use yum I get this error. Config Error: Plugin "replace" requires API 2.6. Supported API is 2.5. I'm new to CentOS ...
0
votes
2answers
1k 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
640 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 ...
0
votes
1answer
940 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
1answer
336 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? ...
3
votes
2answers
196 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+...