Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

Hey, Scripting Guy! How Can I Modify a Text File Based on the Value of a Particular Column in the File?

(image) Hey, Scripting Guy! I need some help in cleaning up a text file. I have a file that contains multiple columns of data, and I need to either delete or modify lines in the file based on the value of the 13th column. Can you help me?-- AM (image) (image) (image) Hey, AM. You know, usually we start off this column with some amusing (well...

Hey, Scripting Guy! How Can I Add a Line to the Beginning of a Text File And Simultaneously Delete the Last Line of That File?

(image) Hey, Scripting Guy! I have a script that adds a line to a log file. Each time I add a new line to this file I would like to delete the last line in the file; that way I always have 20 lines in the file. Can you help me get this to work?-- HW(image) (image) (image) Hey, HW. Well, today is Friday, June 6th, which means that the ...

Hey, Scripting Guy! How Can I Extract Miscellaneous Computer Names From a Text File?

(image) Hey, Scripting Guy! I have a text file containing thousands of events. I need to read each line in that file and look for the name of the computer where an operation failed. The computer names can – and will – vary in length; however, the name will always begin in character position 37, and be followed by the word failed. Oh, and...

Hey, Scripting Guy! How Can I Search a Text File for Activities That Took Place on a Specified Date?

(image) Hey, Scripting Guy! I’m trying to write a script that can go through a log file and determine the number of users who logged off on a particular day. Can you help me?-- TM(image) (image) (image) Hey, TM. You know, when you work at Microsoft people think you probably come to work in your pajamas, ride a unicycle through the ...

How Can I Use Windows PowerShell to Report Back the Name and Creation Date for Files Containing a Specified String Value?

(image) Hey, Scripting Guy! Using Windows PowerShell, how can I search for a string value in all the files in a folder full of text files, then report back the file name and creation date for each file where that string value was found? Oh, and I’d like to have these files sorted by date, too.-- JS(image) (image) (image) Hey, JS. You ...