0

We have a txt file that is getting populated by a database dump, but there are CR and LF breaks, that we don't want. Basically, I am trying to edit C:\app.txt, remove all CRs and LFs, and then add !@# in front of "_TEXT_", and add a CR in front of "!@#_TEXT_". This way, I only have CR in the places I want them, not all over the place.

I have tried using change.exe by Bruce Gunthrie, which worked well in a 32 bit environment, but doesn't work on a 64bit PC.

Any help would be greatly appreciated.

I saw some similar posts here, but have trouble reading the codes because they are too complex, so I didn't know how to adapt them for our environment.

Thanks

Luke

eg.

_TEXT_ data data1
data2 data3 data4
_TEXT_ data data1
data2 data3 data4

Should read:

_TEXT_ data data1 data2 data3 data4
_TEXT_ data data1 data2 data3 data4
4

1 に答える 1

1

PowerShell はオプションですか? (現在の Windows バージョンの 64 ビット コンピューターにはPowerShell がインストールされていると思います。)

$(
  $line = ''
  switch -wildcard -File C:\app.txt {
    '_TEXT_*' {
      if ($line) { $line }
      $line = "!@#$_"
    }
    default {
      $line += ' ' + $_
    }
  }
  if ($line) { $line }
) -join "`r"

これにより、必要に応じて CR で行が結合されます。結果をパイプしSet-Contentてファイルに書き込みます。

于 2012-07-24T09:27:38.290 に答える