I have a txt file like this but I need to add a tab if there are 7 or less characters (including the wrapped double quotes) in EACH of the entries in the LIST column and then replace into file so it formats pretty (this file can only be txt, in the format it currently is in, etc):
Current
List: ID:
"izzak" "QWERTY654POI"
"swortz23" "00ERTY654POI"
"campingou" "QWERTY454POI"
"dark1est" "QWERTY654POI"
"muffin0" "QWERTY654POI"
"parly" "25ERTY654POI"
"ggghsle" "QWE78Y654POI"
"fie4lder" "QWERTY654POI"
"67532" "QWERTY654POI"
"urquhart" "11ERTY654POI"
"bbs3" "QWERTY654POI"
Needs to look like this:
List: ID:
"izzak" "QWERTY654POI"
"swortz23" "00ERTY654POI"
"campingou" "QWERTY454POI"
"dark1est" "QWERTY654POI"
"muffin0" "QWERTY654POI"
"parly" "25ERTY654POI"
"ggghsle" "QWE78Y654POI"
"fie4lder" "QWERTY654POI"
"67532" "QWERTY654POI"
"urquhart" "11ERTY654POI"
"bbs3" "QWERTY654POI"
$where = Get-Content C:\Users\me\Desktop\info.txt
#pull any text on each line before a tab (gets first column if wrapped in double quotes)
$pattern = '(".*")(?:\t)'
$arrayoutput = (Get-Content -Path "C:\Users\me\Desktop\info.txt" | Select-String $pattern -AllMatches | ForEach-Object { $_.Matches.Value }).Trim()
foreach ($product in $arrayoutput) {
if ($product.length -le 7) {
$addtab = "$product"+"`t"
$endresult = $where.replace($product, $addtab)
}
}
$endresult | Set-Content -Path "C:\Users\me\Desktop\info.txt"
Results look like this (where the last line gets tabbed but no others):
"izzak" "QWERTY654POI"
"swortz23" "00ERTY654POI"
"campingou" "QWERTY454POI"
"dark1est" "QWERTY654POI"
"muffin0" "QWERTY654POI"
"parly" "25ERTY654POI"
"ggghsle" "QWE78Y654POI"
"fie4lder" "QWERTY654POI"
"67532" "QWERTY654POI"
"urquhart" "11ERTY654POI"
"bbs3" "QWERTY654POI"
My code will only add a tab to the LAST entry if there are multiple entries in the LIST column less than or equal to 7 (counting the double quotes around it; 5 otherwise).
Anyone have any thoughts on this or how to iterate through each array entry and then replace the old entry with the new?
EDIT: Every line is single tab delimited between the 2 columns.