Skip to content
Advertisement

Tag: sed

Remove newline before a match – Linux

I want to remove the newline before the </script> in my HTML file with a Linux command (sed, awk…). Sample input: Sample output: I tried different syntax, but none of them could do. Answer First of all, as mentioned in the comments Don’t parse XML with Regex! Never do it, never think about it. Make it a habit not to

Can ‘sed’ do ‘or’ class trimming?

I am working with a piece of code but it’s ugly. It has a nasty line in it along the lines of: If any of BE2, RS, etc. are found then it will replaced with Alpha Beta Gamma COM/DLX/BE4/BE2/RS. However, if all three are found then each one will be replaced. Since the ideal output would be: is there anyway

Replace string pattern with a string in linux file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago. Improve this question I am a newbie to Linux. Need to replace With using sed or some alternative. Answer Command that given desired

sed for print two different word alernatively

I have a requirement to print two different words in alternative white spaces in the file. For example, The above scenario, I want print ab and /ab alternatively like below: *I want this one by one in a line by line format(Not horizontal format).*I know sed ‘s|^[[:blank:]]*$|</ab>|’ this command is almost near to my case. But I don’t know how

Replace certain line in a text with a certain line in another text

Taking off from this question, I want to replace a certain line in one text file with another line from another text file. Example: text1 contains: text2: I want to replace the 2nd line in text1 with the second line from text2, the solution in the above mentioned question works by adding all the content of text2 in place of

Sed with special caracters

How can I replace this with sed ? I need to replace this: to Please note that I can’t sed the enabled to disabled because it’s not only used at this location in the input file. I tried this but it didn’t change anything but gave me no error: Answer You can just use the following sed command: CMD: Explanations:

Advertisement