Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
3answers
2k views

How to replace empty cells of a specific column

I have a file with many columns and some empty cells in different columns. I would like to replace the empty cells for NA only in the third column. My file: 1 id1 info 2 otherinfo 3 id2 4 ...
0
votes
1answer
4k views

Replacing a Part of URL String in a Linux File With Another String

I have an HTML file on a Linux server that contains a long list of links. I am trying to edit this file as follows. Find original occurrences of this type: http://www.test.org/name Replace them with: ...
1
vote
3answers
161 views

Replace characters at a specific index counted from behind

I want to change some characters in a string I create. I make a filelisting and from each file I need to append the "stat" information. For example filename "K181_111126.CATProduct" results in "...
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 ...
0
votes
2answers
973 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
313 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
366 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
926 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
130 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
75 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
456 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
554 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
1k 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
528 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
31 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
599 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
843 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
220 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
200 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
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 ...
3
votes
0answers
309 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
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 ...
2
votes
0answers
180 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
120 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
530 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
187 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
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....
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 ...
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 --> .....
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
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
498 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
740 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
22k 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
548 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
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 '\...
3
votes
3answers
567 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
285 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 ...
18
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 ...
1
vote
3answers
775 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
820 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 ...