This question already has answers here:
Counting characters in a specific text file
(4 answers)
Closed 4 years ago.
I have data in a file like below.
text1|text2
text3|text4|
I'm looking for a Power Shell command to count number of pipes present in thisfile.
Normally I would want you to show some effort but this is trivial enough I won't bother:
$pipeCount = (get-content file.txt -Raw).Split('|').count - 1
$pipeCount
Related
This question already has answers here:
.* matches 2 times
(2 answers)
Why do regex engines allow / automatically attempt matching at the end of the input string?
(6 answers)
Closed 6 months ago.
I want to ls -name a folder and wrap the result between the quotes`. However the result make an extra quote after.
> (ls -name) -replace '(.*)', '"$1"'
"apple"""
"orange"""
"dog"""
"cat"""
Why is that?
This question already has answers here:
Dynamically create variables in PowerShell
(1 answer)
Create an incrementing variable from 2 variables in PowerShell
(2 answers)
Closed 10 months ago.
I looking for this in powershell
$VAR0=args[0]
$VAR1=args[1]
$VAR2=args[2]
With a construction like this
$a=0
$VAR+$a=args[$a]
but I cannot concatenate this way
This question already has answers here:
Get only filename from full path of a file
(2 answers)
Closed 5 years ago.
I'm writing a PowerShell script to output the process,
$Process=chknull $_.Properties[0].Value
$Process_new=$Process -replace '(?<! .*) ','_'
The above code outputs the result as entire path of process, Eg:
C:\Windows\System32\Notepad.exe.
Is there a way, where I can get just "Notepad.exe"
If you're getting a full path return like that as a string you can set the value into a variable and then use split on it and grab the last entry in the resulting array.
Example:
("C:\Windows\System32\Notepad.exe." -split "\\")[-1]
Remember to use two "\" as it is also an escape character in regex.
([IO.FileInfo]"C:\Windows\System32\Notepad.exe").Name
This question already has answers here:
How do I split a string into an array by comma but ignore commas inside double quotes?
(7 answers)
Closed 8 years ago.
I want to split a csv file. ex a row contain name,id,address,pin etc..... if the adress contains again commas then how to parse? ex: Abc,123,"xyz,asd,pqr",123456 "xyz,asd,pqr" is one element and kept in double quotes only
Use a CSV parser. If you don't want to install new modules for some reason then look at Text::ParseWords instead.
This question already has answers here:
using wildcard in the dir locations and find all files with an extension
(2 answers)
Closed 9 years ago.
my #hex_locations = ("$FindBin::Bin/../../../project/platform-aa-full/bb",
"$FindBin::Bin/../../../project/platform-aa-base/bb");
how do I use wild card to match any directory with project/platform-aa-* in above code?
Use glob
my #hex_locations = glob("$FindBin::Bin/../../../project/platform-aa-*/bb");