Computing.Net > Forums > Programming > read 12th character of a file

read 12th character of a file

Reply to Message Icon

Original Message
Name: cobramis
Date: December 18, 2007 at 08:42:40 Pacific
Subject: read 12th character of a file
OS: Any
CPU/Ram: Any
Model/Manufacturer: Any
Comment:

I need a batch file that will read the 12th character of the first line of a text file. Then I will do something based off of its value. Is this possible? I have been trying to formulate something with the FOR command but have failed.

Thanks,
Matt
matt@cobra.com


Report Offensive Message For Removal

Response Number 1
Name: tonysathre
Date: December 18, 2007 at 10:43:22 Pacific
Subject: read 12th character of a file
Reply: (edit)

This will set the 12th character or the first line of the text file test.txt to the var %char%.


@echo off
set /p line=<test.txt
for /f "tokens=*" %%i in ('echo %line%') do (
set char=%%i
)
set char=%char:~11,1%
echo %char%


"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 2
Name: cobramis
Date: December 18, 2007 at 11:48:27 Pacific
Subject: read 12th character of a file
Reply: (edit)

Perfect. Thanks!


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: December 18, 2007 at 18:17:31 Pacific
Subject: read 12th character of a file
Reply: (edit)

Wait, I'm confused; what's the purpose of the FOR?


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: December 19, 2007 at 02:02:18 Pacific
Subject: read 12th character of a file
Reply: (edit)

"Wait, I'm confused; what's the purpose of the FOR?"

I'm glad it's not just me.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: tonysathre
Date: December 20, 2007 at 08:05:08 Pacific
Subject: read 12th character of a file
Reply: (edit)

Sorry, got ahead of myself. I'm still learning. Everything I know about batch scripting, I learned from M2, dtech (which I never see here anymore) IVO, and Razor. Thanks guy.

Let me fix it.

@echo off
set /p line=<test.txt
set char=%line:~11,1%
echo %char%

"Foolproof systems don't take into account the ingenuity of fools."


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: read 12th character of a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software