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.
Read vaiable from txt file
Name: burtcampbell Date: June 9, 2009 at 10:35:01 Pacific OS: Windows XP Subcategory: Batch
Comment:
I have a txt file that is formated like this: BackupSet Name= CsComputer, ID= 1149451491216 BackupSet Name= MacBook, ID= 1225425991161 BackupSet Name= Office Desktop, ID= 1234397390047 BackupSet Name= File Demo, ID= 1244129637412 BackupSet Name= SQL Demo, ID= 1244556292461
I need to be able to read this txt file from a batch program, find a specific string like "File Demo", then return the last 13 characters of that line, which happen to be the BackupSet ID. Or if its better to to grab everything after the "=" and trim the space.
@echo off
for /F "tokens=2 delims==" %%j in ('type "MyFile.txt" ^| find "%Name%"') do set ID=%%j
set ID=%ID:~1%
The above script, assuming the variable Name contains the required string, returns the number in ID. That requires just ONE line holds the target string, otherwise the code must be rearranged.
0
Response Number 2
Name: ghostdog Date: June 9, 2009 at 17:22:34 Pacific
Reply:
if you have Python on Windows:
for line in open("file.txt"):
ID=line.split()[-1]
print ID
Summary: I'm trying to read single lines from a text file and store each line in a variable so that I can use that variable to do something (such as COPY, RENAME, MOVE, etc). Here is the operation I want: 1) R...
Summary: hi guys, The input file is coming like ddddddd zzzzzzz ROW_NUMBER,NAME,SAL 1,aaa,5000 I need to read data from the file from the column name ROW_NUMBER. Expecting result: ROW_NUMBER,NAME,SAL 1,aaa,500...
Summary: Hi , i am having this problem of extracting data out from txt file being seperated by ¨;¨. Example: How is your day?;Fine Where are you now?;At your house My code is as follow: char *ques[20]; char...