The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
2answers
22 views

Delete rows from postgres database contain string/sentence [on hold]

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
46 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
35 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
26 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} ...
1
vote
1answer
39 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
4answers
66 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
49 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
34 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
36 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
36 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
187 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 ...
-3
votes
1answer
34 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
81 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
49 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 ...
-1
votes
1answer
47 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
49 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
43 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
3answers
267 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
23 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
78 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
68 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
54 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
35 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
229 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
40 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
31 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
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 ...
0
votes
1answer
60 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
78 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
23 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
90 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 ...
2
votes
2answers
152 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
31 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?
0
votes
0answers
283 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
75 views

Bad Substitution when Renaming Files using find

I am trying to recursively rename image files using the find command. Currently, the command is written as follows: $ find . -name '*.jpg' -exec rename "${echo $(uuidgen) | cut -c1-8}.jpg" '{}' \; ...
2
votes
1answer
71 views

Find and replace using parts of the found string in the replace string

Let foo be any string. I have to search a file for all occurrences of \LeftLabel{foo} and replace each occurrence with \LeftLabel{\textsf{foo}} but only if foo does not start with a $ ...
0
votes
2answers
22 views

Surround a pattern, not changing it, while searching for it case-insensitively

Sorry if this has been asked before, but I haven't found anything so far. Here's the thing: I have a string and a pattern, and want to surround the pattern inside the string with brackets. While I ...
1
vote
3answers
64 views

Is it possible to make sed doing some logic in the replacement part (regex group)

I have few sed command: to extract relevant information My file sample.log (format is ncsa.log) looks like: 2012_04_01_filename.log:29874:192.168.1.12 - - [16/Aug/2012:12:54:21 +0000] "GET ...
0
votes
2answers
65 views

how replace exact word using sed which starts with special character "

I need to replace a word "/hotel to "/Tay I used various delimiters like ? $ but I couldn't get it
1
vote
1answer
32 views

Replace values in a table

I have a table (ascii format with space delimiter), as follow: 1 1 1900 111 1 2 1900 121 1 3 1900 145 1 4 1900 1.45e 07 1 5 1900 5.21e 25 1 6 1900 152 I would like, that if there is a fifth column ...
2
votes
3answers
82 views

How can I use (sed|awk) to mask an e-mail address with asterisks like <j******e@g***.com>

How can I mask a list of e-mail addresses like: John Doe <john.doe@gmail.com> John Doe <johndoe@hotmail.net> Jane Doe <j.doe@outlook.org> ... with sed (or awk) into something ...
1
vote
3answers
127 views

Change name of directories and included file

In a directory I have several sub-directories named as follow (the [1-9] means going from 1 to 9): AA_BB_CC_river[1-9] Each sub-directories contains a file (ascii) having exactly the same name as ...
2
votes
2answers
78 views

Replacing matching text after two matching lines

I have a YAML file which includes a stanza looks this: admin::common::passwords: alice: password: '$6$oTQhLvN/4VFJPscD$8LYwUMSFi' bob: password: '$6$JKOtLF0wHeZfIskt$W/M5.ugDS' If the ...
3
votes
1answer
55 views

Recursive find/replace, taking directory depth into consideration

I've had good luck doing basic find/replace: find . -name "*.php" -exec sed -i -e "s/<?php include 'http:\/\/www/<?php include '..\//g" \{\} \; I am wondering if there is a way to achieve a ...
4
votes
3answers
179 views

Remove long string from files

Files on my server have been corrupted. I want to remove a 13000 character string from all PHP files containing it. The string looks like: ?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { ...
0
votes
1answer
41 views

Can you replace displayed text with something else in command window?

I am trying to manage user accounts. They are basically just numbers, but I would rather see user last names on the screen. Is it possible to automatically replace displayed text with something else? ...
0
votes
2answers
62 views

sed search and replace problem

I am trying to replace a string from a file which contains '&' in its value. vari = '111|abc & efg|123' varj = '222|abc & efg|123' echo $vari | sed -e "s/$vari/$varj/g" output is ...
0
votes
1answer
48 views

How can I replace a filename with .ear in a file-list using sed?

I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear ... I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck: ...