Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Parse Fixed With Text File with regex replace with trimming option... (no looping logic)

$
0
0

Fixed Width text file

  1. 111   2222  333       444444
  2. 555   6666  777 8888

 Desired output

  1. "111","2222","333","444444"
  2. "555","6666","777","8888"

$str ='111   2222  333       444444'
$regex = [regex]'(.{5})(.{5})(.{4})(.+)?'
$replace = '"$1","$2","$3","$4"'
$str -replace $regex,$replace

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles