This question already has answers here:
How can I replace each newline (\n) with a space using sed?
(43 answers)
Closed 7 years ago.
Have output from sed:
http://sitename.com/galleries/83450
72-profile
Those two strings should be merged into one and separated with space like:
http://sitename.com/galleries/83450 72-profile
Two strings are pipelined to tr in order to replace newline with space:
tr '\n' ' '
And it's not working, the result is the same as input.
Indicating space with ASCII code '\032' results in replacing \n with non-printable characters.
What's wrong? I'm using Git Bash on Windows.
Best guess is you are on windows and your line ending settings are set for windows.
See this topic: How to change line-ending settings
or use:
tr '\r\n' ' '
Related
This question already has answers here:
How to use sed/grep to extract text between two words?
(14 answers)
Closed last year.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
I would like to keep the strings between (FROM and as), and (From and newline character).
Input:
FROM some_registry as registry1
FROM another_registry
Output:
some_registry
another_registry
Using the following sed command, I can extract the strings. Is there a way to combine the two sed commands?
sed -e 's/.*FROM \(.*\) as.*/\1/' | sed s/"FROM "//
Merging into one regex expression is hard here because POSIX regex does not support lazy quantifiers.
With GNU sed, you can pass the command as
sed 's/.*FROM \(.*\) as.*/\1/;s/FROM //' file
See this online demo.
However, if you have a GNU grep you can use a bit more precise expression:
#!/bin/bash
s='FROM some_registry as registry1
From another_registry'
grep -oP '(?i)\bFROM\s+\K.*?(?=\s+as\b|$)' <<< "$s"
See the online demo. Details:
(?i) - case insensitive matching ON
\b - a word boundary
FROM - a word
\s+ - one or more whitespaces
\K - "forget" all text matched so far
.*? - any zero or more chars other than line break chars as few as possible
(?=\s+as\b|$) - a positive lookahead that matches a location immediately followed with one or more whitespaces and then a whole word as, or end of string.
This question already has an answer here:
Regex for matching Unicode pattern
(1 answer)
Closed 2 years ago.
I have a text file with lots of unicode escaped sequence (of emojis by the way), for instance
blablabla \uD83D\uDC4D\uD83C blablabla \uDFFC\uD83D\uDC4F\uD83C\uDFFD
I'd like to remove it all, and get
blablabla blablabla
Is there Any regex expression which would clean these considering that i use Notepad++?
Thanks.
I would suggest: \\u[0-9A-F]{4}\s?.
\\u escapes the slash and matches it and the u literal. [0-9A-F]{4} matches exactly 4 of these characters. Perhaps you should update it to also match length 2 characters depending on the actual text: \\u([0-9A-F]{4}|[0-9A-F]{2})\s?
The \s? matches zero or more whitespace so you don't end up with multiple consecutive whitespace characters.
This question already has answers here:
Regular Expression, remove everything after last forward slash
(5 answers)
Closed 3 years ago.
I am trying to get the syntax right so that I can make scanning-client-container-0.2.tar look like scanning-client-container
I am using the delimiter " - " like so:
sed -e 's/-[^*]*$//'
with the result scanning, which is cut off too early
You can use a negated character class in your regex:
sed 's/-[^-]*$//' <<< 'scanning-client-container-0.2.tar'
scanning-client-container
RegEx Details:
-: Match a -
[^-]*: Match 0 or more characters that are not -
$: Match end
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I came across someone doing: grep -v "\#". Could someone just quickly explain what happens when you precede a character that is not an escape character (like '#') with a backslash.
\# is a regular expression which matches the literal character #. Infact the backslash is not needed since the regular expression # is simpler and serves the same purpose.
This question already has answers here:
Split a string by whitespace, keeping quoted segments, allowing escaped quotes
(4 answers)
Closed 8 years ago.
If my input string is:
Word "Two Words" Quo\"te "Quo\"ted Words"
The output should be:
Word Two Words Quo"te Quo"ted Words.
I can't seem to work in the escaped quotes in my regex.
split using this pattern (?<!\\)".*?(?<!\\)"(*SKIP)(*F)|\s
Demo