Saved Bookmarks
| 1. |
Solve : DOS script to read a text file? |
|
Answer» Hi For eg. I have the 1st line in the text as abcd :1234 C:\>type seven.bat Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%i in (seven.txt) do ( echo %%i set seven=%%i set seven=!seven:~6,4! echo seven = !seven! echo seven > !seven!.txt dir !seven!.txt ) Output: C:\> seven.bat abcd :1234 seven = 1234 Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\ 03/02/2010 07:24 PM 8 1234.txt 1 File(s) 8 bytes 0 Dir(s) 299,228,622,848 bytes free C:\> Input: C:\>type seven.txt abcd :1234 C:\> reference: http://www.dostips.com/DtTipsStringManipulation.php#Snippets.RightString Quote from: dos_help on March 02, 2010, 05:02:12 PM I am using for/f statement and i am not able to extract the 7th character.use for loop with variable %%a, set delims=":" , tokens=1,2 , then get %%b inside the for loop Quote from: dos_help on March 02, 2010, 05:02:12 PM I need a batch file to read the 1st line in a text and save that as another text file. C:\>type ghost32.bat Code: [Select]echo off setlocal enabledelayedexpansion for /f "tokens=1,2 delims=:" %%a in (seven.txt) do ( echo %%a %%b set seven=%%b echo seven = !seven! echo seven > "!seven!.txt" dir "!seven!.txt" ) rem use for loop with variable %%a, set delims=":" , tokens=1,2 , rem then get %%b inside the for loop Output: C:\> ghost32.bat abcd 1234 seven = 1234 Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\ 03/02/2010 08:35 PM 8 1234 .txt 1 File(s) 8 bytes C:\> Quote from: dos_help on March 02, 2010, 05:02:12 PM I need a batch file to read the 1st line in a text and save that as another text file. C:\>type sed32.bat Code: [Select]echo off sed s/"abcd :1234"/1234/g seven.txt 1> seven7.txt set /p seven=<seven7.txt echo seven=%seven% type seven7.txt echo Hello > %seven%.txt dir "%seven%.txt" Output: C:\>sed32.bat seven=1234 1234 Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\ 03/02/2010 08:35 PM 8 1234 .txt 1 File(s) 8 bytes 0 Dir(s) 299,224,727,552 bytes free C:\>this looks so familar, greg = bill ? Quote from: ghostdog74 on March 02, 2010, 09:07:46 PM this looks so familar, greg = bill ? he goes by MANY names, apparently. Quote from: BC_Programmer on March 02, 2010, 09:24:38 PM he goes by many names, apparently.i wonder why he has so many names. did he get banned everytime? Quote from: dos_help on March 02, 2010, 05:02:12 PM I need a batch file to read the 1st line in a text and save that as another text file. I'm sorry your thread has veered of topic. I hope you have enough information to solve your problem. Off topic posts should use PRIVATE mail. Good luck Quote from: ghostdog74 on March 02, 2010, 09:31:19 PM i wonder why he has so many names. did he get banned everytime?I think so. He's used so many accounts so far, there's no real difference here. Quote from: Helpmeh on March 03, 2010, 03:47:47 PM He's used so many accounts so far, there's no real difference here. Off topic comments should be sent by private mail. p.s.: BillRichardson's account is still ACTIVE. Summary - BillRichardson Picture/Text Name: BillRichardson Posts: 194 (2.694 per day) Position: Intermediate Thanked: 15 Date Registered: December 21, 2009, 08:19:08 AM -------------------------------------------------------------------------------- There APPEARS to be no reason for a ban. |
|