Scripting Blog [archived]

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

Hey, Scripting Guy! How Can I Search for a Word in a Text File and Return the Entire Line Where That Word Was Found?

(image) Hey, Scripting Guy! I have a scenario in which I need to read a list of names from a text file. I then need to search for each of those names in a second text file; if a name is found I need to extract the entire line in which that name appears. I’ve figured out how to search for a name in a text file, but I can’t figure out how ...

Hey, Scripting Guy! How Can I Sort a Text File Based on a Specific Column in That File?

(image) Hey, Scripting Guy! I have a text file composed of many different lines; each line has a number of fields, with the fields separated from one another by a tab character. I need to sort this text file based on the value of one of these fields. How can I do that?-- IR(image) (image) (image) Hey, IR. You know, that’s an interesting ...

Hey, Scripting Guy! How Can I Read a Text File and Extract All the Text Enclosed in Double Quote Marks?

(image) Hey, Scripting Guy! I’m trying to write a script that can extract all the values found between a set of double quote marks. I know how to read the text file, and I know how to output any information that I find. However, I can’t figure out how to extract all the characters between a set of double quote marks. Can you help?-- TM(...

Hey, Scripting Guy! How Can I Use Windows PowerShell to Determine the Number of Lines in a Text File?

(image) Hey, Scripting Guy! I’m using Windows PowerShell to determine the record count (i.e., the number of lines) in a text file I just created. If the file has 2 lines, no problem; my script reports back a value of 2. If the file only has 1 line, however, I get back what looks to be the number of characters in the file. In other words, ...

Hey, Scripting Guy! How Can I Parse a Text File and Retrieve All the Information Contained Within Square Brackets?

(image) Hey, Scripting Guy! I need to parse through a text file and extract the information contained within square brackets. So far, however, I haven’t been able to figure out how to do this; that’s because the data isn’t stored on separate lines in the file. Can you help?-- EI(image) (image) (image) Hey, EI. Well, today is Friday, ...