Results 1 to 3 of 3

Thread: How use reg expr to find substring up to indexOf string?

  1. #1

    Default How use reg expr to find substring up to indexOf string?

    I have a bunch of files named "xxxx.idl". I need to pull out the filename without the extension via regualr expression (in the above example, that would be "xxxx"). How do I do this?


    Example:

    File: "SomeFile.idl"
    Result of Reg Expr: "SomeFile"

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,990

    Default Re: How use reg expr to find substring up to indexOf string?

    Must it be a reg expr or is that just another way to say what you want as output?

    Code:
    cd <dir-where-they-are>
    for FILE in *.idl
    do      echo "${FILE%.idl}"
    done
    There is no reg exp in this solution, just file name expansion and parameter value cutoff, so you may not be happy with this.
    Henk van Velden

  3. #3

    Default Re: How use reg expr to find substring up to indexOf string?

    If you just need it for a script, you can simply...
    Code:
    ls *.idl | awk -F. '{print $1}'
    That will list all files ending in .idl, then awk will output the first field using the period '.' as the field separator. From there you can redirect the output wherever you wish. ie.. to a file named 'outputfile' would be...
    Code:
    ls *.idl | awk -F. '{print $1}' > outputfile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •