I'd like to add characters to the end of every line of text in a .txt document.
#Define Variables
$a = c:\foobar.txt
$b = get-content $a
#Define Functions
function append-text
{
foreach-Object
{
add "*"
}
}
#Process Code
$b | append-text
Something like that. Essentially, load a given text file, add a "*" the the end of every single line of text in that text file, save and close.
In PowerShell, string concatenation is primarily achieved by using the “+” operator. There are also other ways like enclosing the strings inside double quotes, using a join operator, or using the -f operator. $str1="My name is vignesh."
No function necessary. This would do it:
$b|foreach {$_ + "*"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With