Skip to main content

Questions tagged [replace]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
3 answers
103 views

sed to replace in a file, with both old and new strings in files

I want to automatically comment out a code block in PHP file, as below: The original block: // Enable all errors ini_set('display_startup_errors', 1); ini_set('display_errors', 1); ...
alancc's user avatar
  • 213
6 votes
3 answers
383 views

zmv: Replace double-quote (") in filename

Using zmv on macOS, I'd like to replace double-quotes (") in filenames with underscores (_). However, I'm having trouble getting the zshexpn to correctly isolate the ". Is there some magical ...
atlauren's user avatar
0 votes
0 answers
92 views

Find and replace in CudaText editor

So I have dump from U-boot and I need to replace specific string in CudaText editor. Here is mine text e101b1e0: 30ef27d8 e792f415 9beea618 5c601de4 .'.0..........`\ e101b1f0: aeaf9d25 e1dd63e9 ...
Slobodan Vidovic's user avatar
1 vote
1 answer
46 views

Search and replace content

PIN A 1 1:3 0:8 0 0:0 PIN B 1 1:0 0 0:0 Z Z:0 PIN C 1 1:3 0:8 0 0:0 Z Z:0 I would like to change the content on PIN A & PIN C only without affecting PIN B to 0 0:3 Z 0:3 Can't seem to find a ...
JSL's user avatar
  • 11
0 votes
1 answer
78 views

How to do replace with the dte editor

The dte editor a small and easy to use console text editor. In readme or its online doc, both says: Regex search and replace (are the key features). However, I haven't found how to do the replace ...
xpt's user avatar
  • 1,644
2 votes
1 answer
115 views

Replacing a character in all files names of a directory

This is homework! I'm trying to replace all spaces in file names with an underscore in the yay directory. It asks me to use the commands xargs and sh without using $(command). I tried using conducts ...
cow's user avatar
  • 81
1 vote
2 answers
48 views

replace both filename and filename's content relying solely on pattern found on the name-of-the-file

I'd like to know if it's possible to replace both filename.ext and a matched pattern inside its content regarding a pattern founded on the filename itself using sed (and grep also, maybe?). Let me ...
dAllARA's user avatar
  • 33
-3 votes
2 answers
93 views

How can find special row and replace special strings

I wrote a todo list script with "add","clear" and "find" argument. I need to pass a "done" argument and script find related row and replace its first column ...
Danial Rostami's user avatar
0 votes
4 answers
452 views

sed: Replacing successful as the condition

I bumped into an excellent use of sed to do replacing, and use its successful state as the condition to print the line: $ seq 3 | sed -n 's/2/B/ p' B I'm wondering if this short form can be extended ...
xpt's user avatar
  • 1,644
0 votes
3 answers
400 views

Adding 10 whitespace characters using sed

I have written a script that replaces a string, but I need to add the 10 whitespace characters back. I can add it back by pressing space 10 times, and that works, but this looks hideous in my script. ...
user898458's user avatar
1 vote
4 answers
324 views

Insert one file's content into another file and replace it between pattern

I have a file1.html: <!doctype html> <html> <head> </head> <body> text <!-- start-replacing --> <p>more text1</p> <p>more text2</p> ...
R 9000's user avatar
  • 167
0 votes
1 answer
157 views

Replacing multiple substrings in a filename with one (bash or zsh)

I have a text file with filenames, where the filenames contain information in various formats (e.g., resolution 4k, 4K, 2160, XxY etc) and I want to rename files to a singular consistent format. When ...
Jorgen's user avatar
  • 3
1 vote
1 answer
238 views

Find and replace a special pattern for all files in a folder

I have a series of files in a common bioinformatic format (FASTA) that consist of a string of: 1 special character ">", text as the sample name (length of the string varies, can include ...
dustonthedash's user avatar
3 votes
5 answers
392 views

Replace empty lines in one file with lines from another file

I have file1.csv "word 1" "" "word 3" "" "word 5" "word 6" and file2.csv "replacement text 1" "replacement text 2" &...
R 9000's user avatar
  • 167
0 votes
1 answer
113 views

How do I find and replace something AFTER a specific term in a terminal output

I need to run blkid and copy a specific UUID after a specific known partition name. Then, I need to paste this into an exists config file, replacing a UUID that it's already there (parent_device_uuid)....
Capybara_Overdose's user avatar
0 votes
2 answers
144 views

Merge two two-column files based on a common first column prefering values from the second column of a given file

I have two text files 1.txt and 2.txt that contain two tab separated columns. The first column of both files consists of tokenized text. In both files, the first column is the same. The word order ...
winety's user avatar
  • 3
2 votes
3 answers
4k views

Replace empty string with text using sed or similar tool

Is it possible to replace an empty string with some text using sed or similar tool? sed 's/^$/sometext/' will match an empty line but that is not what I am looking for. I thought that sed 's//...
fuumind's user avatar
  • 449
0 votes
1 answer
153 views

Find and replace everything inside bracket using unix shell - several lines

I need to find and replace a big part of a json file using shell. For exemple I have this file : { "Balise1": true, "Balise2": true, "OtherThingEnabled": false, ...
Raph04's user avatar
  • 3
1 vote
2 answers
123 views

sed -Extended RegEx question here

I feel dumb as a sack of hammers asking this here, but it's been a long day and I simply CANNOT figure out what I'm doing wrong here. I have a file; we'll call it textfile.txt. It's contents are (in ...
NerdyDeeds's user avatar
0 votes
1 answer
174 views

Add one second to yyyymmddhhmmss with awk

I have this file where the seventh field is a yyyymmddhhmmss. I need to increase just one second this number. So far, I've come up with: awk 'BEGIN{FS=OFS="|"} $7=$7+1 ' <file> And ...
Alan Mackey's user avatar
0 votes
1 answer
827 views

ansible lineinfile module to match variable_value

how can one possibly match value of a variable through regex parameter in lineinfile module? - name: emptyline before search lineinfile: dest: ~/file insertbefore: '^{{ search_text }}$' ...
Sollosa's user avatar
  • 1,951
1 vote
1 answer
37 views

Show application list with description, ommitting "nothing appropriate"

I've been working on a script with a variety of functions. I'm trying to add a function that show's the output of the whatis command for all applications in the "/usr/share/applications" ...
Lee's user avatar
  • 97
2 votes
3 answers
481 views

Sed replace the middle string

I have this this String 22<>22 And i have this list test dev too The output should be like 22test22 22dev22 etc.. This is the commands i use for do that cat list | sed 's/$/22/g' | sed 's/^/...
Notme's user avatar
  • 83
2 votes
2 answers
660 views

Delete multiline blocks with sed non-greedy

How can one remove code blocks starting with /** START */ and ending with /** END */ using sed non-greedily considering that code blocks are multiline and empty lines may occur within START-END blocks?...
0x1505's user avatar
  • 23
0 votes
1 answer
89 views

uncomment the line upon search string while ignoring case in a file

Below is my cron file entries: #Ansible: test2 */15 * * * * ansible-playbook /web/playbooks/automation/detect401MORTEN/va_action.yml | tee -a /web/playbooks/automation/detect401MORTEN/cron.out # #...
Ashar's user avatar
  • 511
0 votes
3 answers
2k views

How to replace all matched strings in the files recursively?

There are about 50 HTML/js files in the folder name site, some of the files contain (below lines are combined from files) {"rendered":"http:\/\/localhost:4542\/?page_id=854"} ...
Maxfield's user avatar
  • 161
0 votes
2 answers
244 views

insert block of lines only before first matched pattern

i need to insert the below lines (after variable substitution) before the first matched string which is server { in /etc/nginx/nginx.conf Variable: website=www.hello.com Block of lines: server { # ...
Ashar's user avatar
  • 511
0 votes
1 answer
165 views

Replace text in a file after nth line till the end of file in unix

I have a file File.txt LV_A=1; LV_B=2; LV_C=rr; jfffkf LV_A dndd LV_B hjhf LV_C hjhf LV_Chjhf LV_C hjhf LV_C hjhf LV_C hjhf LV_C etc i will create file call replcae.txt LV_A,1 ...
vijayakumar ponnusamy's user avatar
0 votes
1 answer
583 views

How do recursive replace of string with '?

In a zsh Terminal window under macOS, I'm trying to replace all instances of (Y, d') with \opair{Y, d'} recursively on all .tex files starting in the current directory. The following seems to do ...
murray's user avatar
  • 103
0 votes
4 answers
286 views

can sed add a new line after matching a pattern while not editing line pattern is on?

I need to find a way to add a line to files after a pattern, but I don't want to edit the line the pattern is on. For example, my original file will look something like group: misc host: server1 job: ...
Adam's user avatar
  • 9
0 votes
1 answer
1k views

Include spaces and tabs in "awk" search and replace

Another user helped me earlier to fix something I'm doing with awk, where I search for a string at any point in all files and replace two numbers in the same line when I find it. awk -i inplace '/^...
the_pocket_of_big_noob's user avatar
1 vote
3 answers
141 views

Different $RANDOM results in sed when reading lines in multiple files

I'm trying to run a command that will read multiple files in a directory, look at each line of each file, and whenever it reads a specific string ("gene_height") on any line it replaces 2 ...
the_pocket_of_big_noob's user avatar
1 vote
2 answers
814 views

awk get column value from file 2 for file 1 if value matches in 2 columns [duplicate]

I have 2 files, trying to set column value that is taken from file2 into file1 when their columns match file1: signup||20200620|A3332|en|LA||ACTIVE signup||20200620|B4443|en|CA|66001|ACTIVE signup||...
Sollosa's user avatar
  • 1,951
0 votes
1 answer
105 views

How to replace a string containing date and IP with sed command

I have the following string of characters, including the IP address and date. For some security reasons, I need to hide the first two digits of the IP address. text 200.200.10.2 2022.05.07 15:32:43 ...
xionngle's user avatar
-1 votes
2 answers
166 views

awk bring same field value from file1 and set in file2 [closed]

File1 (parent) 2210 1110 Earth 2211 1111 Marse 2212 1112 Saturn 2213 1113 Pluto File2 (child) 3310 2210 Earth 3311 2210 Space 3312 2211 Mars 3313 2211 Space 3314 2212 Saturn 3315 2212 Space 3316 ...
Sollosa's user avatar
  • 1,951
-1 votes
3 answers
460 views

awk print only modified lines

I have file like this d1000 1000 d1001 100 d1002 10 d1003 1 I want to modify second column where length is not equal 4. But I want to print only lines that are modified, so original text in column 2 ...
Sollosa's user avatar
  • 1,951
13 votes
8 answers
2k views

How can I replace a character within a specific context in each line of the whole file?

I have a large file which contains hundreds of English phrases in the following form: \phrase {. . . * * } {I shoul-d've stayed home.} {aɪ ʃʊd‿əv ˈsteɪd ˈhoʊm.} <- only replace on ...
Zoltan King's user avatar
0 votes
1 answer
140 views

How to replace text in file - conditions and arithmetic required

I need a script to change content in some text files. This a bit beyond my limited bash skills. Maybe perl or python would be a better approach, I have no experience with either of these. I have a ...
jamitin's user avatar
-1 votes
1 answer
52 views

Search & replace for a string separated by whitespace upon substring match found

Below is a sample file content: cat sample.txt -server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler....
Ashar's user avatar
  • 511
0 votes
2 answers
232 views

sed and awk in sh script not replacing text

The desired work to find a string, and replace to another (all occurrencies), and rewrite/update the file too. The file is an pbxproj file. I linked a sample of this file sample of the file (please ...
nszmmp's user avatar
  • 13
1 vote
5 answers
1k views

Replace hyphen(s) with underscore(s) within angle brackets in a file

I’m aware of how to replace string; e.g., replace hyphen with underscore in a file. However, I wish to replace all hyphens with underscore for all text that falls within angle brackets in a given file....
Ashar's user avatar
  • 511
0 votes
4 answers
348 views

Search and Remove Lines of Code from all files

I need help and need to search for and remove a 3 line bit of code from all files in a directory. Code is: if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) )...
Adam Giddens's user avatar
2 votes
3 answers
1k views

Replace dynamic word using sed command

I have a requirement where we need to replace a word in a file which can be different everytime I execute the script, the content of the file is class DynamicContentToReplace > Something Here I ...
curious_dev's user avatar
1 vote
2 answers
769 views

sed replacing a string with itself and a new line

I have the following string multiple times in a html file <br> <h4 id=... Now, I know sed might not be perfect for html editing, but could tell me how can I replace br> <h4 id with br&...
radui's user avatar
  • 111
3 votes
2 answers
4k views

How to substitute non printable characters with space character in a file

I have read nearly every answer about this topic on this website or Stackoverflow but didn't manage to solve the issue below. When I copy the text from a PDF file and paste it into a text file file....
Amazigh_05's user avatar
1 vote
3 answers
942 views

Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String?

Is it possible to Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String? It is possible that the string may contain any decimal value, which needs to be ...
Gary C. New's user avatar
0 votes
1 answer
774 views

Ansible - replace first occurrence of certain expression in file - path includes hostname

I need to replace the first occurrence of a certain string in a specific file. I think about to use the replace module of Ansible for this. - hosts: abc tasks: - name: Replace first occurence of ...
Tobitor's user avatar
  • 125
0 votes
1 answer
100 views

How can I replace a word with another word in a whole hierarchy of files

I have a hierarchy of files and two words: word1 and word2. In this hierarchy of files, some of them can contain word1. I want to replace every occurrence of word1 with word2. It is possible using a ...
Fredi's user avatar
  • 59
-1 votes
1 answer
82 views

How to search and replace text in files but keep/reuse a certain part of text?

I want to refactor many JavaScript files in many directories which contain access to an object in this format: myObj.something.somethingElse and I want it to be myObj.getSomething(somethingElse) how ...
vodofen's user avatar
  • 149
2 votes
3 answers
2k views

find and sed to replace special characters

I'm looking for an easy way to rename many files on my Synology NAS. find and sed are available, but not rename. I can get a list of these files and folders with find . \( -type d -name "@*" ...
Gary U.U. Unixuser's user avatar

1
2 3 4 5
9