Computer Science, asked by Anonymous, 9 months ago

Question :- Make any three consecutive lines as bold.

.☠Spammers Stay away

Quality answer needed✔

Copied paste will be reported❎​

Answers

Answered by Anonymous
0

 \huge{ \underline{ \bold{ᴀɴsᴡᴇʀ....{ \heartsuit}}}}

Simple Answer:

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

$pattern = 'two

three

four' -replace "`r"

file | Select-String file∣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 -match file−matchpattern

file | select-string file∣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 -match file−matchpattern

file | select-string file∣select−stringpattern -quiet

Similar questions