locked
Find a date in txt file RRS feed

  • Question

  • Hi guys!

    Simple question today:

    My txt file is this:

    Title
    
    dd/mm something
    
    dd/mm something else
    

    with powershell i need to know if one of those days is today.

    Can you help me please?

    Thanks

    Friday, July 25, 2014 8:24 AM

Answers

  • $Today=Get-Date -DisplayHint Date -Format 'dd/MM'
    
    
    
    if (findstr /B $Today $Bundle){... }

    This is what i do.

    What do you think about?

    Thanks

    A

    I think about a long vacation on a tropical isle.

    You need to think about what you are trying to do.  What are you trying too do?

    To find strings in file with PowerShell use Select-String.

    See: HELP Select-String -FULL


    ¯\_(ツ)_/¯

    • Marked as answer by Albiz Wednesday, July 30, 2014 7:03 AM
    Monday, July 28, 2014 12:17 PM
  • $stringtosearch = Get-Date -Format 'dd/MM'
    
    Get-Content 'C:\Temp\myfile.txt' | Select-String -Pattern $stringtosearch

    Considering you are searching some text file which has date format as 28/07 - Its not necessarily only date. Your file may have something like 28/07 denoting some codes.

    But, I posted the code which give some clue to your requirement.


    Regards Chen V [MCTS SharePoint 2010]

    • Marked as answer by Albiz Wednesday, July 30, 2014 7:02 AM
    Monday, July 28, 2014 2:00 PM

All replies

  • Today is not simple question day.  Tomorrow is simple question day so your question is not so simple.

    What have you tried? 

    Hint: convert datetime object to matching string first.

    $s=[datetime]::Today.ToString('dd/MM')


    ¯\_(ツ)_/¯

    • Proposed as answer by Shaun Vermaak Friday, July 25, 2014 2:50 PM
    Friday, July 25, 2014 8:36 AM
  • $Today=Get-Date -DisplayHint Date -Format 'dd/MM'
    
    
    
    if (findstr /B $Today $Bundle){... }
    

    This is what i do.

    What do you think about?

    Thanks

    A

    Monday, July 28, 2014 8:41 AM
  • $Today=Get-Date -DisplayHint Date -Format 'dd/MM'
    
    
    
    if (findstr /B $Today $Bundle){... }

    This is what i do.

    What do you think about?

    Thanks

    A

    I think about a long vacation on a tropical isle.

    You need to think about what you are trying to do.  What are you trying too do?

    To find strings in file with PowerShell use Select-String.

    See: HELP Select-String -FULL


    ¯\_(ツ)_/¯

    • Marked as answer by Albiz Wednesday, July 30, 2014 7:03 AM
    Monday, July 28, 2014 12:17 PM
  • $stringtosearch = Get-Date -Format 'dd/MM'
    
    Get-Content 'C:\Temp\myfile.txt' | Select-String -Pattern $stringtosearch

    Considering you are searching some text file which has date format as 28/07 - Its not necessarily only date. Your file may have something like 28/07 denoting some codes.

    But, I posted the code which give some clue to your requirement.


    Regards Chen V [MCTS SharePoint 2010]

    • Marked as answer by Albiz Wednesday, July 30, 2014 7:02 AM
    Monday, July 28, 2014 2:00 PM