|
| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
batch file to count lines
|
Original Message
|
Name: Noor2000
Date: September 17, 2004 at 07:51:29 Pacific
Subject: batch file to count lines OS: Windows2000 CPU/Ram: 256
|
Comment: Hi all, The goal is to count how many lines in a files begins with 000(I'using a batch file), I use the command "find" but the problem is It counts not only the lines begining with 000 but also the lines containing 000 Is there a way to resolve that? Thanks for your help
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Mechanix2Go
Date: September 17, 2004 at 08:18:50 Pacific
|
Reply: (edit)Hi Noor, The gotcha is that FIND doesn't have the capability of 'lines beggining with.' You need a 3rd party clone of the unix grep. I use xgrep.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: IVO
Date: September 17, 2004 at 08:22:06 Pacific
|
Reply: (edit)If the lines in the file REALLY begin with 000, i.e. there are no spaces in front of them, the following compound command suffices FindStr /B /C:000 File_Name | Find /C "000" otherwise post again as the solution is a bit more complex.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Noor2000
Date: September 19, 2004 at 18:59:08 Pacific
|
Reply: (edit)Hi all, It works, but how can I send the result in a variable (for example Lines)? As well as I remember this is you Ivo who helped me with this before. Thank you Noor
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: IVO
Date: September 20, 2004 at 01:30:07 Pacific
|
Reply: (edit)Yes Noor I'm back and the following batch is what you need (For /F fits just one line of code) @Echo Off For /F %%A in ('FindStr /B /C:000 %~f1 ^| Find /C "000"') Do Set Lines=%%A Echo Lines=%Lines% Name it CX.bat, type CX File_Name and see how it works. Ciao IVO
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: Noor2000
Date: September 22, 2004 at 08:41:57 Pacific
|
Reply: (edit)Yah but I would like to give the name in the command, I tried but didn't work: For /F %%A in ('FindStr /B /C:000 %~f1 ^| Find /C "000" q_drm.txt') Do Set Lines=%%A Echo Lines=%Lines% The file that I want to count is q_drm.txt, because I don't want to have many batch files
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: IVO
Date: September 22, 2004 at 09:14:32 Pacific
|
Reply: (edit)My script does just that as %~f1 is the parameter you type on the command tail (e.g. CX q_drm.txt)! I don't understand what is your problem as the scripts I post are always tested succesfully before as I do not want anymore people go into troubles due to my tips. Please specify better.
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: Noor2000
Date: September 22, 2004 at 10:38:07 Pacific
|
Reply: (edit)Hi Ivo, Sorry because I was not clear.. well the batch file is counting the number of the lines and then depending on this number I'm calling other scripts. Well I said to myself I would like to reduce the number of the batch files, If I do CX.bat q_drm.txt that will be just a line in another batch file, do you understand me? You remember when you help to add a date in a text file and print the document. I know that you help many people to be more clear the code was: Echo. If "%1"=="" (Echo File missing Please check if the script run today & GoTo :EOF) If not exist %1 (Echo File not found & GoTo :EOF) Set FDate=%~t1 Set FDate=%FDate:~0,6%20%FDate:~6,2% If not "%FDate%"=="%Date:~-10,10%" ( Echo File Date is not To-day Date: %FDate% Set FDate= GoTo :EOF) That works fine but when I want to put it on a server It didn't work because the format of the date on the server is: yyyy-mm-dd and I couldn't change the format on the server, I'm trying to customize in the batch file it but I don't understand the role of t1. Thank you Noor(technicalUser)
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: IVO
Date: September 23, 2004 at 02:40:40 Pacific
|
Reply: (edit)Well Noor, about your question on the FindStr command, if you want the file's name "wired" into the statement, just type in your script For /F %%A in ('FindStr /B /C:000 q_drm.txt ^| Find /C "000" ') Do Set Lines=%%A i.e. replace %~f1 with the desidered file's name. Regarding the question about date's format, as I do not fully understand the root of the problem, could you run (on the wild server!) the following tiny batch and report me the output? Then to address the solution should be a nut. -------- @Echo Off Set FDate=%~t1 Echo [%FDate%] [%Date%] Name it as you want, e.g. Noor.bat, then type Noor File_Name where File_Name is whatever file you like. Ciao IVO
Report Offensive Follow Up For Removal
|
|
Response Number 9
|
Name: Noor2000
Date: September 23, 2004 at 07:24:18 Pacific
|
Reply: (edit)For the first part, I'm going to run it and I let you know. For the secend part I did it and It gave me as a response: [] [Thu 2004-09-23] Thanks a lot Ivo for your help
Report Offensive Follow Up For Removal
|
|
Response Number 10
|
Name: IVO
Date: September 23, 2004 at 08:41:07 Pacific
|
Reply: (edit)Noor, I need you type a valid (i.e. a file that really exists) file name on the command line of Noor.bat (e.g. Noor q_drm.txt) otherwise I can't resolve the FDate variable that is what I need to explore deeper. Working toghether we solve the problems, even if light years away.
Report Offensive Follow Up For Removal
|

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
|
|
|