Recursive Find and Replace using Git Bash on Windows 10


In my previous post I setup virtual TV Shows in Kodi for a couple of YouTube channels that I downloaded videos from.

I copy and pasted a template file to create multiple .nfo files,  but I made a mistake – all of the files have 2019 in one of the text fields instead of 2018!

Fortunately I found a nice quick solution that used Git Bash on Windows 10.

I simply mapped my file share as network drive Y, opened Git Bash,  and issued a couple of commands:

$ cd Y:
$ find . -type f -name "*.nfo" -exec sed -i'' -e 's/2019/2018/g' {} +

Done!

A quick run-down of the commands:

  • change directory to Y: (cd Y:)
  • find
  • file (-type f)
  • named *.nfo
  • run sed (-exec sed)
  • edit in-place (-i)
  • add script (-e ‘)
  • substitute 2019 (s/2019)
  • for 2018 globally (2018/g)

Very nice to be able to use bash inside Windows 10!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s