简体   繁体   中英

How to replace txt file name with data from the text file itself based on regex?

I need to edit a bulk number of txt file names with part of the content inside those files and was wondering if I can use regex with automation software for Mac (maybe Automator or Scrapestorm would be a fit?).

The part that needs to be extracted is in the first part of the text file and it is structured the same

<h1 style="clear:both" id="content-section-0">Text that I want to use for the file name</h1>

Is there anyway to automate this process?

Thanks!

Thanks to @jhnc was able to do it fairly easy. On Mac, just enter terminal, navigate to the specific folder and run this script. Thanks again community!

perl -e 'for(@ARGV){ local(@ARGV,$/)=$_; rename $_,"$1.tx" if <>=~/<h1 style="clear:both" id="content-section-0">([^<]*)</ }' page-*-spin-*.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM