#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Edit a text file -- Please help!


    Hi,

    I have a very large text file on my desktop, with about 2500 lines.

    Each line is quite short, each containing either a song file or movie file, here's a sample list of them:

    Signs 2002 TLKDA9ALKADNCLA0
    Sleuth.1972.882.27fps.562kbs.v7vbr.wunseedee
    Snabba.Cash.2010.SWEDiSH.VID.WpLA

    I need a code that will identify 4 numbers in a row (a date) and remove all characters after that. I want the red text to be removed... This must be repeated for each line (a loop?)

    The second function I need done is to replace underscores "_" with a space, and also I'd like to replace periods "." with a space. I would like the altered text file to then be written back to my desktop.

    So ultimately, the 3 file names above should end up like this in a new text file:

    Signs 2002
    Sleuth 1972
    Snabba Cash 2010

    I'm using TextPad, but have NO idea what type of code to use... or what it should look like. I was only told to use "Regular Expressions"...

    Please help, thanks a lot!!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep Power
    0
    1) Use the following code:

    Code:
    Search for: (?<=\d{4}).*
    Replace with: (empty string)
    TextPad uses POSIX regular expressions, so this probably will not work with it. You can try another editor.

    2) For replacing underscores and periods, you can use the usual search and replace (without regular expressions).

IMN logo majestic logo threadwatch logo seochat tools logo