Linked Questions

2
votes
2answers
2k views

how to remove a multilined string/block of text pattern from a file? [duplicate]

I have a text file that has a multiple lined string of text I'd like to scan the file for and remove all instances that it finds of that multilined and potentially sometimes duplicate string. example ...
-1
votes
1answer
3k views

Using sed to merge two lines [duplicate]

I'm trying to merge these two lines that appear periodically in a text file. travel_ by_night_and_day I have tried: sed '/_\nby/_by/s' input.txt > output.txt but, it doesn't do anything. Do I ...
1
vote
3answers
298 views

How do I replace this pattern with a newline inside it? [duplicate]

If I have a text file with this content: someline <!--\ file first read on 2015/01/11 And I want to delete <!--\ and everything until what comes after "on", how do I do it? The ...
0
votes
1answer
33 views

Finding and replacing text when there are custom elements within [duplicate]

I have about 450 html files I need to edit. I have the directory they all are in, so that narrows things down from the perspective of searching. What needs to be changed is a bit of known text, some ...
12
votes
7answers
2k views

How can I delete all characters falling under /* … */ including /* & */?

I did tried sed and awk, but its not working as the character involves "/" which is already there in command as delimiter. Please let me know how can I achieve this. Below is a sample Example.We ...
15
votes
3answers
22k views

Replace multiline string in files

I have a number of files I want to update by replacing one multi-line string with another multi-line string. Something along the lines of: * Some text, * something else * another thing And I want ...
8
votes
3answers
13k views

How can I use sed or ex to replace a block (multi-line code) with new block of text (code)?

I have to replace a large block of a text (shell script code) in a file with another block of text. I am impressed with the How can I use sed to replace a multi-line string? answered by antak and ...
3
votes
2answers
12k views

Search replace in XML file with sed or awk

So I have a task where by I have to manipulate an XML file through a bash shell script. Here are the steps: Query XML file for a value. Take the value and cross reference it to find a new value from ...
6
votes
1answer
2k views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
3
votes
1answer
2k views

How to combine strings from JSON values, keeping only part of the string?

I have sample: "name": "The title of website", "sync_transaction_version": "1", "type": "url", "url": "https://url_of_website" I want to get the following ...
2
votes
1answer
2k views

Strings replace in bash using multiple lines pattern

How can I do a string replace in bash using multiple lines pattern? To illustrate I present a pseudocode: TARGET_STR=' $N = "magic_quotes_gpc = <b>"._("On")."</b>"; $D = _("...
3
votes
3answers
766 views

Using sed to remove string or paragraph between delimiter

I would like to know who to remove a string or paragraph that are between ((( string ))) Lorem ipsum (((dolor sit amet))), consectetur adipiscing elit. Vestibulum aliquet fringilla est, dictum ...
3
votes
2answers
101 views

Using sed to edit a string over two lines

I have a file which includes consecutive lines like this macroa{abc def 123 ghi} macrob{abc 123 xyz} I want to check if the first string in macrob is the same as in macroa and if it is to delete it ...
1
vote
4answers
73 views

How can I use sed to insert some text after a multiline match?

I have a file sample.txt like this: lots of text lots of text #nvram = [ # these # could # be, # anything #] lots of text lots of text and I want to add some text "foobar" to get this: ...
1
vote
1answer
238 views

multiline sed substitution overwrites previous output

I am trying to do a sed substitution over two lines like this: sed -r '/user-type/{N;s/user-type: (.*)\n.*gth: .*([0-9]+).*$/\1 \2/}' I got this syntax from an answer here, which explains I first ...

15 30 50 per page