# Parsing text files

Microsoft Windows xp professional w/serv...
March 29, 2010 at 06:11:40
Specs: Windows XP, 2.5ghz
 Hi,I've been searching and have been unable to figure out how to remove the first blank line, the second line that starts with dashes and the cn: from each entry. Here is what I get after running an ldifde export:---------- C:\TORONTO_LAPTOPS.LDFcn: 13LLJH1cn: 1897QJ1cn: 33R0QJ1cn: 375RNH1cn: 3HPP3G1cn: 4ZXKBF1cn: 57LFRD1cn: 5B983F1cn: 68LFRD1I just want a batch file that gives me the entries after cn: I just want a text file that looks like this...13LLJH11897QJ133R0QJ1375RNH13HPP3G14ZXKBF157LFRD15B983F168LFRD1Thank you for any help!Steveosux

See More: Parsing text files

#1
March 29, 2010 at 06:33:36
 Name the batch as you like then type e.g. mybatch File_Name to get the result in output.txt@echo off > output.txt for /F "skip=1 tokens=2" %%j in ('type "%*"') do echo.%%j>> output.txt If the dash line is retained replace skip=1 with skip=2

Report •

#2
March 29, 2010 at 06:39:28
 @echo off > newfile & setLocal enableDELAYedeXpansionfor /f "skip=1 tokens=* delims= " %%a in (my.LDF) do (set S=%%aset S=!S:~4!>> newfile echo.!S!)=====================================Helping others achieve escape felicityM2

Report •

#3
March 29, 2010 at 07:32:12
 OMG! Thank you both for your help. I actually used Mechanix2Go's suggestion with IVO's tweek of skip=2 to get rid of the first instead of ---------- C:\TORONTO_LAPTOPS.LDF line in the file. Works perfectly. I should have just asked for help a few days ago...I guess that's why my name is steveosux.

Report •

Related Solutions

#4
March 29, 2010 at 08:06:54
 download sed for windows, and then use this one linerC:\test>sed -n "2,\$s/^cn:[ \t]*//p" file 13LLJH1 1897QJ1 33R0QJ1 375RNH1 3HPP3G1 4ZXKBF1 57LFRD1 5B983F1 68LFRD1  GNU win32 packages | Gawk|

Report •

#5
March 30, 2010 at 05:31:54
 So I was thinking that I would like to combine a little of yesterday's post with another command. Here is what I would like to try to accomplish...Take the ldifde output after the computer names are parsed, ping them once and if there is a reply from the remote computer, reg query them for a specific software.Here is what I have so far, but don't know how to combine the two correctly.This will ping each machine in my text file and output the name and IP to a CSV file...@echo offset ComputerList=C:\path\to\computer\list.txtEcho Computername,IP Address>Final.csvsetlocal enabledelayedexpansionfor /f "usebackq tokens=*" %%A in ("%ComputerList%") do (for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^|findstr Reply') do (set IPadd=%%Becho %%A,!IPadd:~0,-1!>>final.csv))I would like to add either command to the file...I just want to run the below command on responding computers...it would be great if I could run this scan over and over and append to the bottom of the CSV since machines may be on at different times of the day.reg query \\computername\HKLM\Software\Lotus\Notes /v Versionor WMIC /Node:%ComputerName% product where "Name like '%Lotus%'" get Name, Version Thanks for any support!

Report •

#6
March 30, 2010 at 08:58:32
 tentative stab, not tested:@echo off > newfile & setLocal enableDELAYedeXpansion>> logfile echo %date% %time%for /f "skip=1 tokens=* delims= " %%a in (my.LDF) do (set S=%%aset S=!S:~4!for /f "tokens=*" %%a in ('ping -n 1 !S! ^|find /i "lost = 0"') do set xx=%errorlevel%if %errorlevel% equ 0 (reg query \\!S!\HKLM\Software\Lotus\Notes /v Version >>logfile) else (>> logfile echo !S! offline)::------- end -----use the AT daemon to reschedule at intervals. If you want a clock-bump batch (add xx minutes to curr.time) let me know.

Report •

#7
March 30, 2010 at 11:21:27
 Thank you. I tried the file and didn't really have much luck. The ping piece works good though.I did make a few change to your suggestion to make this:@echo offset ComputerList=C:\TEXTFILE.txtEcho Computername,IP Address>Final.csvsetlocal enabledelayedexpansionfor /f "usebackq tokens=*" %%A in ("%ComputerList%") do (for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^|findstr Reply') do (reg query \\%%A\HKLM\Software\Lotus\Notes /v Version >>logfile>> logfile echo %%B is offlineset IPadd=%%Becho %%A,!IPadd:~0,-1!!>>final.csv))This gives me two files - a CSV and a logfile...both of which give me information that I can't use. The reg query finds the version of the Lotus Notes, but in the output doesn't associate the version that it found with a machine name...So it tells me that I have version 8.5.1 on a machine, but nothing to identify that name....What about something that reg query's a list of computers and then dumps the following into a CSV file...if the computer is reachable, it would put the following in a file:Computer name IP VersionIf the computer is not reachable, it should still be listed in the CSV file with "Offline" in one of the columns.Thank you - Thank you - Thank you...hope I'm not asking for the world...

Report •