Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
3answers
130 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 ...
0
votes
2answers
934 views

Replace a field only for lines beginning with a string with a defined string

Here is the file I need to deal with. ENR1;203023;0000;H606626;001505;EL;00;1234;0000100;00;00;201346100;H6022418; ENR6;000218;130155;000;00;201443;000000000;000000000;000000000;000000000; ENR1;...
0
votes
1answer
297 views

Replace spaces with sed and regexp grouping not working

Somewhy replace empty chars (space, tab, etc.) is not working with sed and regexp grouping: sed -i "s|dir(\s*)=(\s*)'${site_path_source}'|dir$1=$2'${site_path_target}'|g" The whole line does replace ...
0
votes
3answers
345 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::...
1
vote
2answers
902 views

multiple replacements on single line with sed

I would like to scan a whole file tree and do two replacements any line with two matches, i.e.: printf("Hello WORLD! %s, %d\n",bcm_errstr(rv),var); dprintf("kjhgjkhfkhgfjgd %s\n",bcm_errstr(rv)); ...
2
votes
3answers
126 views

Find and Replace Everything Before a String of Text

I have a large list of IP addresses (most are IPv4, but a few are IPv6), followed by a space and then a domain name, followed by another space and the same domain name with "www." in front of it. Each ...
0
votes
2answers
73 views

How to use sed to replace strings with categories?

I have some categories and their values: Category: Value: 1*4 15.934934 1*5*3 19.281281 1*8*10*2 78.20912 I would like to replace the categories by numbers that represent the ...
-1
votes
3answers
2k views

How can I use sed to replace a specific pattern and add exceptions in the same line?

I am using sed to look for and replace a pattern. My pattern is "-" I have the following data >1-2-3-4-5 29238232382083e-9 >1-2-3-4-5 29238232382083e-9 >1-2-3-4-5 ...
1
vote
2answers
447 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$...
2
votes
2answers
543 views

How to replace all occurrences in a file with unique value for each occurrence

I am having one xml file which has multiple occurrences MyID as shown below. MyID="dett090900990000" I want to replace all occurrences of MyID="" value with unique value. For e.g. if I have three ...
0
votes
2answers
989 views

Replace comma delimited file with pipe, but not remove comma or quotes etc within text qualifier field, however, remove text qualifier!

My file is a comma delimited file and text qualifier is ~, but my requirement is to find and replace comma delimited file with |(pipe) delimited file and remove text qualifier ~ with nothing, however, ...
0
votes
2answers
510 views

Find words after specific symbol on line

I need to make a bash script that reads a file containing variable = text. What I need is for the script to check the file, ignore the variable name and search for a word in the text after the = ...
-2
votes
1answer
30 views

Replacing rows from one file with rows from other file [closed]

I am thinking how can I replace a portion of a file -- let's say lines from m to n with lines from other file and do this in an nice manner. I however don't want to ...
2
votes
2answers
561 views

Procedure to replace a hard disk?

One of the HDs in our Linux Mint computer has been behaving strangely (see at the end of the post, but it's not relevant) so we have decided to replace it. I would appreciate some advice on how to do ...
0
votes
1answer
816 views

replace unix variable with value into sql file

I have sql file with multiple unix variable to spool the log into specific location and need to replace the unix variable with actual path before running sql file `cat a.sql accept v_answer prompt "...
1
vote
2answers
209 views

Search and replace is not respecting my “$1” token

Using bash shell on Ubuntu 14.04. Trying to do a simple search and replace on every line of a file. I have tried perl -pi -e "s/.*/DELETE FROM my_object_times where ID = '$1';/g" ids.csv but this ...
0
votes
1answer
191 views

Replacing text between two specific strings

I have large number of files that have an deprecated css value "hspace" and I want to change it with other css style value. Here is an example: we have: hspace='5' and we want to change with: style=...
-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 ...
2
votes
2answers
433 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 ...
3
votes
0answers
296 views

KVM/QEMU hot-replace raw disk

One of VM disks got damaged and I'm trying to replace it online, without rebooting VM. However when I use: drive_add virtio1 file=/dev/sdb,format=raw,if=virtio,cache=none,aio=native in VM monitor ...
1
vote
2answers
243 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 ...
2
votes
0answers
174 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
103 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
1answer
526 views

How do I replace tokens from one file with data from another?

I'm using Amazon Linux with bash shell. I have a file with comma delimited data, where each row looks like this 2049,576804C7DF554416A9EA25B2A5A81514,X, Then I have a second file, with comma ...
-1
votes
1answer
183 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 ...
2
votes
3answers
277 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....
2
votes
1answer
54 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
276 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 --> .....
4
votes
4answers
4k views

Btrfs RAID1: How to replace a disk drive that is physically no more there?

I have a btrfs RAID1 system with the following state: # btrfs filesystem show Label: none uuid: 975bdbb3-9a9c-4a72-ad67-6cda545fda5e Total devices 2 FS bytes used 1.65TiB devid 1 ...
1
vote
1answer
83 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
492 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,...
0
votes
1answer
720 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: /...
8
votes
6answers
20k 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 ...
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/...
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
529 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
1answer
42 views

Add the set of commands at the beginning of multipls files

I need to write a script for replacing a part of file with other. I am handling hundreds of files. I have a list of commands to be added to a bunch of text files. But in the files I have a common ...
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
485 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
95 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 '\...
3
votes
3answers
536 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
278 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 ...
17
votes
1answer
15k 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
3answers
740 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
809 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
521 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 ...