locked
Pick a string not whole the line containing that string..Help! RRS feed

  • Question

  • Hi everybody, I am new to this forum. Now I have a trouble and need your helps.

    For example: I have a text file (text.txt) containg string : "aaaaaaaaaaaaaa computer adsfjasldkfjasjflk asdlfkjwoeifj 12345"

    My Object is to use command line to output only string "12345"

    I tried to use command findstr "[1-9]$" C:\123\text.txt. The output of command is exactly the whole line containing the string "12345" not

    the string "12345" as I want.

    Anyone have better idea?

    Thank for any suggest.

     

    Monday, January 30, 2012 6:38 AM

All replies

  • Asuming the following points,  below command will work for you

    1. The digit part is always at the end of the string.

    2. The digit part is at fixed position like if a split the string by space , it will come on 5th position.

    --------------

    @echo off

    FOR /F "tokens=1-5" %%A IN ('findstr "[1-9]" C:\123\text.txt') DO @echo %%E

    ---------------

    This will pick the line where the digits were found and then split it in 5 parts and finaly echo the last part which is actulay having the digits. So the output will be 12345 only.

    Try It , Good Luck !!

    Shantanu

    Thursday, February 2, 2012 2:37 PM