Computing.Net > Forums > Programming > Get last 4 character from a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Get last 4 character from a file

Reply to Message Icon

Name: joshie
Date: August 11, 2009 at 04:31:21 Pacific
OS: Windows XP
Product: Focus enhancement Tview micro presenter win/dos tv scan converter vga
Subcategory: Batch
Comment:

Hi Guys,
I'm a newbie to batch programming.
I had created a batch file to read a line from a text file. example: Hello world 1234
However i would like to pass the last 4 characters to a variable.

Any help is greatly appreciated



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: August 11, 2009 at 06:26:01 Pacific
Reply:

If the text file holds ONE line only, the following script does the job

@echo off & setlocal
set /P myvar=< "MyFile.txt"
set myvar=%myvar:~-4%
echo.%myvar%
:: End_Of_Batch

If however the file holds multiple lines, a For /F loop is needed and the line identified in some way.

0

Response Number 2
Name: joshie
Date: August 11, 2009 at 17:57:48 Pacific
Reply:

Thanks IVO, that works for me.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Get last 4 character from a file

Perl: Stripping last 4 characters from string www.computing.net/answers/programming/perl-stripping-last-4-characters-from-string/19568.html

To get the last 10 lines of a file. www.computing.net/answers/programming/to-get-the-last-10-lines-of-a-file/20114.html

read from a file... Fortran or C www.computing.net/answers/programming/read-from-a-file-fortran-or-c/576.html