Computer Science, asked by Anonymous, 7 months ago

Question :- Make any three consecutive lines as bold.

.☠Spammers Stay away

Quality answer needed✔

Copied paste will be reported❎


50 points Question Don't spam here​

Answers

Answered by jyotigupta64
1

Simple Answer:

$file = (Get-Content -Raw file.txt) -replace "`r" # removing "`r" if present

$pattern = 'two

three

four' -replace "`r"

file | Select-Stringfile∣Select−Stringpattern -Quiet -SimpleMatch

RE-EDIT. Wow. This is a tricky way to do it. At the prompt, $pattern has no "`r", but in a script it does. This should work as a script or at the prompt.

$file = (get-content -raw file.txt) -replace "`r"

$pattern = 'two

three

four' -replace "`r"

# just showing what they really are

$file -replace "`r",'\r' -replace "`n",'\n'

$pattern -replace "`r",'\r' -replace "`n",'\n'

# 4 ways to do it

file -matchfile−matchpattern

file | select-stringfile∣select−stringpattern -quiet -simplematch

file -like "*file−like"∗pattern*"

file.contains(file.contains(pattern)

# output

one\ntwo\nthree\nfour\nfive\n

two\nthree\nfour

True

True

True

True

Hmm, trying a regex way. In single line mode, a . can match a "`r" or a "`n".

$file = get-content -raw file.txt

$pattern = '(?s)two.{1,2}three.{1,2}four'

# $pattern = 'two\r?\nthree\r?\nfour'

# $pattern = 'two\r\nthree\r\nfour'

# $pattern = 'two\nthree\nfour'

file -matchfile−matchpattern

file | select-stringfile∣select−stringpattern -quiet

{\huge{\sf{\red{\underline{\underline{ᴀɴsᴡᴇʀ}}}}}}

ᴀɴsᴡᴇʀ

Answered by Anonymous
0

$file = (Get-Content -Raw file.txt) -replace "`r" # removing "`r" if present

$pattern = 'two

three

four' -replace "`r"

$file | Select-String $pattern -Quiet -SimpleMatch

RE-EDIT. Wow. This is a tricky way to do it. At the prompt, $pattern has no "`r", but in a script it does. This should work as a script or at the prompt.

$file = (get-content -raw file.txt) -replace "`r"

$pattern = 'two

three

four' -replace "`r"

# just showing what they really are

$file -replace "`r",'\r' -replace "`n",'\n'

$pattern -replace "`r",'\r' -replace "`n",'\n'

# 4 ways to do it

$file -match $pattern

$file | select-string $pattern -quiet -simplematch

$file -like "*$pattern*"

$file.contains($pattern)

# output

one\ntwo\nthree\nfour\nfive\n

two\nthree\nfour

True

True

True

True

Hmm, trying a regex way. In single line mode, a . can match a "`r" or a "`n".

$file = get-content -raw file.txt

$pattern = '(?s)two.{1,2}three.{1,2}four'

# $pattern = 'two\r?\nthree\r?\nfour'

# $pattern = 'two\r\nthree\r\nfour'

# $pattern = 'two\nthree\nfour'

$file -match $pattern

$file | select-string $pattern -quiet

{\huge{\sf{\red{\underline{\underline{ᴀɴsᴡᴇʀ}}}}}}

✔ Hope this will help you :)

Similar questions