The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
2answers
59 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
21 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
70 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 ...
1
vote
1answer
46 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
18 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
40 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
36 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
49 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
53 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
42 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
26 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
58 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
122 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
49 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
34 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
142 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
39 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
55 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
39 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: ...
1
vote
1answer
49 views

Replace or modify file contents at one shot

I have file where I need to modify some lines for every account. The line which I need to modify looks like as below: PstlInfo <some content> NNYYYN (Every account will have this line) the ...
4
votes
3answers
279 views

Convert genotypes to 0/1

I have a file that looks like: 1 rs6687776 1020428 T C T C T C C C T C C C T C The 4th and 5th column are the two different possible alleles at that ...
0
votes
2answers
104 views

Use multiple commands in sed to insert text after string with special characters

I am having a little trouble trying to do a search and replace using sed in a config file. I want to use multiple commands using the -e option to do the following. Step 1: find the first occurrence ...
2
votes
1answer
60 views

Sed: replace text keeping digit occurrence

I have some text like: Blablabla <b>[intlink id="</b>2204<b>" type="page"] Blalala I want replace it for remove the </b> and <b>, keeping the id="number". So it should ...
1
vote
1answer
35 views

How to query-replace after a given character in a string?

How to replace all / by . only in the sentence after the = ? For example, from this: /buttress_unit/buttress_top/buttress_i_ps_but_cio_m1_i_but_m1_tx_wrapper_m1_pref_fifo_array_29__stream_id_3_0 = ...
0
votes
1answer
61 views

Replace the first word of each line with its MD5

I have file with two space separated word in each line. I am looking for shell scrip in Unix to replace the first word of each row with its md5 hash representation. I have tried to adjust what is ...
-3
votes
1answer
94 views

How can i replace a specific string within a line inside a text file [duplicate]

$ cat text.txt my name is Steven my age is 10 i like dogs What command will be fitting so that echo "Kate" will replace Steven on text.txt?
0
votes
1answer
94 views

How to replace \1\ with new line

I have a record like: "evSchema"\1\"UAT" "evSN"\1\"uadb" "evDirsep"\1\"/" "evRootPath"\1\"/work_area/APP_UAT/" "evSchema"\1\"RMS13" "evUser"\1\"STAGE" I want to replace \1\ with new line. I tried ...
2
votes
2answers
95 views

How to replace value for a given condition in specific column of file

I have file separetd by pipe | and I want that when column 6 contain letter I print 0758000 in column 7 and when the column 6 contain letter A print 0800000 in column 7, I can not find how to do it!!! ...
0
votes
1answer
187 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 ...
0
votes
1answer
200 views

How to replace the content of specific column with awk? Tab Delimited File

Here's a similar question but I ran into a problem that was not addressed in the question. How to replace the content of specific column with awk? I want to do something similar, however my file is ...
1
vote
2answers
33 views

Sed Replace Around Numeric Content

I'm modifying an html output <td nowrap align="right">4683</td> I'd like to replace all occurrences in the document matching this pattern, where 4683 may be any given number varying in ...
0
votes
3answers
81 views

How to substitute a string in file with another file?

I have several files that all contain a string. This string needs to be replaced by the whole content of another file (that can possibly be multi-line). How can I do this? What I need is something ...
0
votes
1answer
49 views

How can I use sed to find a string and replace another string on a different line? [closed]

I have a file like this: BEGIN Name "TIPO_RECORD" SqlType "12" Precision "255" Name "Test" SqlType "12" Precision "255" Name "xxxx" SqlType "12" Precision ...
0
votes
1answer
622 views

How to replace multiple occurrences of a pattern with sed

I use the following command to remove surrounding spaces between array keys that are strings or integers in PHP files: sed -ri "s/\[ ([0-9]+|(\x27|\x22).*(\x27|\x22)) \]/[\1]/g" file.php I thought I ...
4
votes
2answers
392 views

Awk inplace option with print statement

In recent version of awk there is a inplace option that can be used to do in place operations similar to sed's -i option. However I can't make it work with print statement. Let's see my example. The ...
0
votes
0answers
20 views

Sed replace with command output [duplicate]

I'm trying to replace text with the contents of a file and I'm getting errors. This works: cat /tmp/test | sed -e "s/__TEST__/$(cat pass)/g" But this one doesn't cat /tmp/test | sed -e ...
1
vote
1answer
64 views

Pattern matching and removal of that pattern using sed

I have 2 files with the following names: File 1: RvA_X-IRB-bil-CA101-0+010000-20150327212332-055582-P File 2: RvA_X-IRB-bil-CA101-1+020000-20150327212332-055582-P I am using this command to match ...
0
votes
2answers
71 views

Search a line and replace line

false###File.txt many rows ###online = false --> ONE SHOT import (delete all table contents before importing) ###online = true --> DIFFERENTIAL import (import without clean the table contents) ...
2
votes
2answers
345 views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
0
votes
1answer
40 views

Emacs: query-replace prepend text to the found string

The scenario is that I am trying to append a new class to all the style declrations in my css file. So .oldclass{ float : left; } should change to .newclass .oldclass{ float : left; } The ...
-1
votes
1answer
98 views

replace text in a file

are there any usefull command to replace all text that contain number and remove those number . Ex: myimages-202x250.jpg width="202" heignt="250" replace to myimages.jpg width="217" height="317" ...
2
votes
0answers
197 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 ...
3
votes
1answer
99 views

Find/replace on block device?

Let's say I have an unmounted block device /dev/sda, and I want to replace all instances of MyPassWord with XXXXXXXXXX. (Hopefully my goal is obvious.) What's the easiest way to do this?
2
votes
2answers
87 views

Search and Replace question

I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD. So AAHelloBB Text AAByeByeBB becomes CCHelloDD Text CCByeByeDD. It's important to note ...
1
vote
2answers
75 views

find and replace a value in a line of text

I have a text file which contain only 1 line of text 1314:Battery:1.90:50:30 I'm trying to figure out if is there anyway to do a grep and sed to change the value 50 and 30 to the following ...
1
vote
2answers
615 views

How do you search and replace multiple lines in KDE Kate?

how do you replace multiple lines of code in Kate? The following is the original text: <div id="image"> <br style="clear: left"/> <br style="clear: left"/> <br style="clear: ...
1
vote
1answer
158 views

substitute complex text string in several files that contains special characters

I need to replace a complex string in several files in a directory. The string that needs replaced is: ...
0
votes
2answers
42 views

iterate lines containing zeros in bash

I am having a file which looks like this: 141.519 141.009 140.121 135.519 0 0 0 0 I'm writing a shell script and I want to replace all lines containing a zero with -1e+10. So far, I’ve tried this: ...
-1
votes
1answer
472 views

how to replace a specific pattern from all files [duplicate]

suppose I want to replace abc with xyz in all files in a directory. How do I write a script for this ?