4

I have a large 55 GB file in which there is a sentence on every line. I want to check if there are any lines that have a dot "." at the end, and then if there is, I want to insert a space before the dot in that line.

Ex: I like that car. Replace with: I like that car .

A space before the trailing dot on every line if there is a dot.

I don't have any cygwin or unix and I use a windows OS. Is there a sed like common that I can do on this 55GB! file?

I tried GetGNUWin32 but I am unable to determine the actual command there.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
London guy
  • 27,522
  • 44
  • 121
  • 179

3 Answers3

4

Install Perl. Strawberry Perl is probably the best distribution for Windows. http://strawberryperl.com/

To do what you're talking about in Perl, it would be this:

perl -p -i -e's/\.$/ ./' filename
Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • i tried and it didnt do anything on windows 7, after some experimenting i found that i had to use double quotes " instead of singe quotes '. – peter Dec 01 '20 at 20:22
3

You can install Cygwin and use sed from there. And here I found Sed for Windows


Edit:
Very Good Answers to your Question: Is there any sed like utility for cmd.exe

(I always prefix stackoverfloew when I search on google. Same I did for you on google: sed on window stackoverflow, but that is different matter)

Community
  • 1
  • 1
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
2

For your use case:

From PowerShell.exe (comes with Windows)

(Get-Content file.txt) -Replace '\.$', ' .' | Set-Content file.txt

I searched for hours and hours and had so much trouble trying to find a solution to my use case, so I hope adding this answer helps someone else in the same situation.

For those who got here to figure out git filter clean/smudge like I did, here's how I finally managed it:

In file: .gitconfig (global)

[filter "replacePassword"]
    required = true
    clean = "PowerShell -Command \"(Get-Content " %f ") -Replace 'this is a password', 'this is NOT a password'\""
    smudge = "PowerShell -Command \"(Get-Content " %f ") -Replace 'this is NOT a password', 'this is a password'\""

Please note that this snippet doesn't change the original file (this is intended for my use case).

Additional search terms to help those looking: interpolation, interpolate

CalamitousCode
  • 1,324
  • 1
  • 14
  • 21