The tag has no usage guidance.

learn more… | top users | synonyms

3
votes
2answers
142 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 ...
2
votes
1answer
51 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
45 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
1answer
547 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
51 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 ...
2
votes
5answers
95 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 ...
0
votes
3answers
65 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
46 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
43 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 ...
9
votes
2answers
993 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
27 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 ...
21
votes
2answers
80k views

How to insert text after a certain string in a file?

Right now I'm using echo "Hello World" >> file.txt to append some text to a file but I also need to add text below a certain string let's say "[option]", is it possible with sed? EG: Input ...
0
votes
2answers
37 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
76 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
61 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
53 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
54 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
37 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
113 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 ...
0
votes
2answers
42 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
51 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
72 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
32 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 ...
1
vote
4answers
238 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 ...
20
votes
12answers
22k views

How can I “cat” a file and remove commented lines?

I'd like to know if there is a way that I could cat file like php.ini and remove all lines starting with ; For example, if the file contained this: ; - Show all errors, except for notices ; ;...
3
votes
2answers
188 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
51 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
84 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 ...
13
votes
1answer
18k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
2
votes
3answers
515 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
2answers
52 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
55 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
64 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
46 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
1
vote
1answer
27 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
105 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
70 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
80 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
39 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
1answer
54 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
33 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 ...
3
votes
2answers
549 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 ...
1
vote
2answers
87 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 ...
0
votes
2answers
25 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 Kate 15.08.2, is it possible to search for [[i]] in each file and ...
0
votes
4answers
96 views

How can I replace a character in all the .php files inside a folder on OS X?

I need to replace the following characters: ă with a â with a î with i ș with s ț with t The replacement must be case sensitive. For example if a letter is upper-case then it must be replaced ...
17
votes
6answers
4k views

How to replace current word under cursor in Emacs

How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. ...
1
vote
2answers
46 views

Replace characters in Makefile target

I'm trying to use $(patsubst %-%,%:%,$(MAKECMDGOALS)) to replace dashes with colons in the make target but it has no effect. How could I achieve this?