All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
4answers
45 views

Find and replace after a string after a specific character

I have the following lines in my input file and I would like to replace all the text after "=" sign with a new string, say "good". Again, I would like to do this only for certain strings in the line....
0
votes
1answer
55 views

Extracting multiple strings, according to a pattern, in a bash script

I'm writing a shell script to generate a directory listing. as an input a receive a long html string : https://www.mycompany.com/posts/aureliaflore_china-seoul-startup-activity-6571925510337728512-...
1
vote
1answer
27 views

Bash replace special character '

All the questions and answers i already read are not my solution. So, all i want to do is to replace the special char ' in bash. This works: A="abc" B="${A//[b]/x}" But this does not work: A="a'b" ...
1
vote
4answers
67 views

Replace string in multiple files (same directory) with condition

Example: File1: Name: abc Number: 325 Code: 0 File2: Name: xyz Number: 578 Code: 0 File3: Name: ttt Number: 356 Code: 0 File4: Name: nnn Number: 228 Code: 0 File5: Name: bnb Number: 434 Code:...
1
vote
3answers
110 views

How to find and replace seemingly a tab char using sed?

I have a line looks like this: some.com *.some.com The space is seemingly a tab space because when I move the keyboard arrow, one move will move me to the end of it (it does not seem multiple ...
0
votes
1answer
32 views

How to search for a newline that is not preceeded by } and remove it

I want to use sed to search for line breaks that are not preceded by }. The regex for identifying theses cases is: [^}]$ . What I want to say: If the line ended without } then remove the new line. ...
0
votes
3answers
58 views

How to keep the content of a replaced string with sed

I am trying to use sed to replace a line of text that will keep the found text intact and add a colon to the end of it. specifically, in a file there are a bunch of lines in this format ...
2
votes
2answers
271 views

Bash replace string at multiple places in a file from command line

I have a file with the below content. I want to replace chrome with chromeBackup but not in all places. Name=chrome XXXXXXXXXXX Run=bin -app "chrome/chrome.sh" XXXXXXXXXXX Vol.apps/chrome=chrome ...
1
vote
2answers
116 views

sed: strip enclosing square brackets

I have this file: [default] region = us-east-1 output = json [profile automation] region = us-east-1 output = json [profile qa] region = us-east-1 output = json I need to extract only the profile ...
0
votes
1answer
61 views

korn shell Unable to substitute ' ' (2 quotes) with ' (single quote) in a string variable

I am trying to substitute ''2019-01-14'' to '2019-01-14' in a varible $STG. I tried various techniques echo ${STG//''/'} echo $STG | sed -e s/'\'\''/'\''/g many more none of the equations are ...
0
votes
1answer
38 views

find and replace a substring and change to uppercase

I think it's best done with an example Contents of my file name="apple" parameter1="value1" parameter2="value2"; name="orange" parameter1="value1" parameter2="value2"; name="tea" parameter1="value1" ...
1
vote
1answer
82 views

How to Replace a string by another in a text file

I would like to replace a given string in a text file into by another, but with one extra detail. Example: If the file content's is : Library Hello1 =============== any text here version: 0.1 ------...
0
votes
3answers
162 views

Can I use sed/awk/etc to replace parts of a file with text from stdin?

I have a configuration script which does basically this: #!/bin/bash source vars.sh cat >foo.output <<EOF # some static stuff (many lines...) variable_bit=($SOME_VAR, $SOME_OTHER_VAR, ...) ...
1
vote
1answer
42 views

Replace literal space with regex space

I want to change a string from This is a string to This\sis\sa\sstring but tr is not working for me no matter if I escape the \ or not string="This is a string" regex=$(echo "$string" | tr " " "\\...
1
vote
1answer
39 views

Search and replace substring with an other in all the files of a folder and all its subfolders

I know there are several questions as this one, but mine is specific: I want to replace the substring: localhost:8000/ with https://www.begueradj.com/ in all the HTML files existing in a folder and ...
0
votes
1answer
193 views

Running several sed commands on same files simultaneously

To change all occurences of the string foo to bar in all files in a directory I use sed -i -- 's/foo/bar/g' * Found that here But I also want to change NAME to name etc. I tried, sed -i -- 's/foo/...
11
votes
6answers
3k views

In `sed` how can I put one “&” between characters in a string?

Can sed make something like : 12345 become : 1&2&3&4&5 ?
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: ...
0
votes
1answer
73 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? ...
1
vote
1answer
107 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 ...
5
votes
2answers
2k views

Replace very long string in files recursively

I have a very long and complex string in many files and I want to remove/replace it recursively. The string contains many slashes, backslashes and spaces and any kind of special signs. How do I do ...
11
votes
3answers
15k views

Replace multiple strings in a single pass

I'm looking for a way to replace placeholder strings in a template file with concrete values, with common Unix tools (bash, sed, awk, maybe perl). It is important that the replacement is done in a ...
8
votes
3answers
2k views

How to remove a specific character in a string but only if there are no numbers in that line in Linux

I've been stumped with this seemingly simple-to-fix problem.. well, for a while. Here's example output from the file I need to edit: $cat file George Washington Geneva Convention 123,281,029 USD 342,...
2
votes
0answers
222 views

Automatic replacement of strings in gedit

I want to replace some strings defined by me in gedit, after a word has been completed and/or the document has been saved. For example \ðrac should be replaced with \frac How do I do this in gedit or ...
3
votes
2answers
1k views

remove only specific text occurrences from string using sed

I have a text file that contains many rows of this sort of thing: /*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36'; Is there a way that I can use sed to remove ...
5
votes
4answers
2k views

Replace whole line in a file from command-line

I have a text file which has some contents similar to this: # General information about the project. project = u'Py6S' copyright = u'2012, Robin Wilson' # The version info for the project you're ...
2
votes
1answer
862 views

Replace complex string in several files

A hacker got into a web server and added this string (removed some characters for security purposes and added line breaks for readability) in all index.php files: <?php eval(gzuncompress(...
3
votes
4answers
2k views

Collapse repeating characters

Is there a more Bashist way than echo "$PWD//" | sed -e 's#//\+#/#g' to replace repeating slashes with a single one? Thanks Steven D, now there's a fully working function to find the longest common ...