I’m parsing the output of a HTTP GET request with sed to retrieve the contents of a given html tag. The result of that request is like this: “<!DOCTYPE html><html><body><h1>Hello!</h1><p>v1.0.4-b</p></body></html>” And I want to retrieve the version number inside the p element. However, sed seems to have a bug in regex parsing. When I use: sed ‘s/.*<p>//’ It correctly replaces
Tag: sed
Find and replace words using sed command not working
I have a a text file which is tab separated, the first column holds the word to be found and the second column holds the word to replace the found word. This text file contains English and Arabic pairs. Once the word is found and replaced it should not be changed again. For example: So for a given text file:
Remove eveything before including colon and replace comma to newline
I am looking just to accommodate my query into one-liner. I have a below file content where i want to remove all before last colon(:) including itself and then replace comma(,) into newline to get the desired results. these all comma separated values are linux user ID’s File content: Already tried: working solution: result: Is there a better trick, please
How to replace newlines between brackets
I have log file similar to this format Here is the echo command to produce that output $ echo -e “test {nseq-cont {nttt0,nttt67,nttt266nttt},nttgrp-id 505nt}n}ntest{nttest1{nttvalnt}n}n” Question is how to remove all whitespace between seq-cont { and the next } that may be multiple in the file. I want the output to be like this. Preferably use sed to produce the output.
linux replace string in files recursively
I have a folder which is full of *.java files. it has the following method in it: i wanted to change this as following: I have searched in the forum and found some solutions, replce string is what i wanted so tried the following: But it throwing me the following error: I guess the old_string and new_string formates are the
Use values in a column to separate strings in another column in bash
I am trying to separate a column of strings using the values from another column, maybe an example will be easier for you to understand. The input is a table, with strings in column 2 separated with a comma ,. The third column is the field number that should be outputted, with , as the delimited in the second column.
Replacing line of text cointing using sed
I’m trying to replace document.querySelector(‘.popup’).classList.add(‘active’) by document.querySelector(‘.popup’).classList.add(‘noactive’) Answer You can use See the online demo. The regex is POSIX BRE compliant and matches (document.querySelector(‘.popup’).classList.add(‘) – Group 1 (1): a literal document.querySelector(‘.popup’).classList.add(‘ text (active’)) – Group 2 (2): a literal active’) text. Note the capturing groups in a POSIX BRE regex are set with (…). The literal dots need escaping and
How to split a text file into blocks with 10+ characters without dividing words using sed in Linux?
I want to come up with a sed command where once every 10 character will look for the nearest space and substitute it with “|” I tried sed -E -e ‘s/ /|/( *?[0-9a-zA-Z]*){10,}’ new.file, but it shows errors. Example input: Expected Output: Answer This works for given sample: (.{10}[^ ]*) this matches 10 characters, followed by any non-space characters then
Replacing a string in the beginning of some rows in two columns with another string in linux
I have a tab separated text file. In column 1 and 2 there are family and individual ids that start with a character followed by number as follow: I would like to replace NA with HG in both the columns. I am very new to linux and tried the following code and some others: Any help is highly appreciated. Answer
To read desired values from file using linux system commands (grep,awk,sed) [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 1 year ago. Improve this question I have file test.txt contains some variables assigned to some value, i need to read all defined variables for example