powershell v2.0 - I would like to read content of txt file ends it with ( ; ) semi-colon character -
i have txt
file has 50 long character in line1 but, want read first 10 11 or less character , end on semi-colon.
basically, want characters before semi-colon.
first.txt
1234567891;45416564653afsd
second.txt
124562;455466asdfa
appreciate anyone's help..
the following returns portion of each line input file file
before first ;
.
if there no ;
entire line returned.
get-content file | foreach-object { ($psitem -split ';')[0] }
to give sense of elasticity of powershell, can rewrite following more terse form, utilizing built-in aliases (though it's better verbose , avoid aliases in scripts):
gc file | % { ($_ -split ';')[0] }
Comments
Post a Comment