Help setting variable to second line of a txt

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Help setting variable to second line of a txt

Post by MigrationUser »

20 Nov 2015 15:36
mfrancke

Let me preface, I've only been in software packaging a couple years and that has been the breadth of my cmd experience.

This little bit is almost just an exercise for me so I can engage in a larger project soon after. I can't set an environmental variable to a line of a txt... depicted below. I was hoping to grab the contents of the second line of data from a file retrieved from a wmic query.

Image

for /f "delims=" %a in (file.txt) do set var=%a

Was my reference>

What small stupid thing am I missing?

----------------------------
25 Nov 2015 23:59
Shadow Thief


I have figured out your problem!

You've saved file.txt as Unicode instead of ANSI. The command prompt doesn't play nice with Unicode (or UTF-8).
Image

The simple solution is to save your text files with ANSI encoding when you're using Notepad.
Image

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

#17 26 Nov 2015 06:46
foxidrive
Shadow Thief wrote:

You've saved file.txt as Unicode instead of ANSI.
Good sleuthing there Shadow Thief. :)

This is going to be a similar headache because of wmic - not insurmountable but it's there.
mfrancke wrote:

I was hoping to grab the contents of the second line of data from a file retrieved from a wmic query.
Post Reply