Need help text parsing string

Microsoft Windows xp pro with sp3 multil...
February 3, 2010 at 10:22:53
Specs: Windows XP
I have a text file that need to clean up. For the most part it is CSV format, however there are several instances where a little cleanup is required. I have several strings similar to this

TCP,12.20.34.120:11038,0.0.0.0:0,,LISTENING,8288
OracleServiceAPPS2
[System]

That I would like to look like this

TCP,12.20.34.120:11038,0.0.0.0:0,,LISTENING,8288,OracleServiceAPPS2 [System]

There are two patterns that I need to find and replace the first is the combination of a # followed by a return. I need to replace this with a ,

The second pattern is a return followed by a [. I need to replace this with a space.

I am assuming that I can do this with some sort of FOR command, I'm just not sure how to go about setting it up.

Help


See More: Need help text parsing string

Report •


#1
February 3, 2010 at 10:40:14
How big are the files?


=====================================
Helping others achieve escape felicity

M2


Report •

#2
February 3, 2010 at 10:43:23
about 12K lines

Report •

#3
February 3, 2010 at 12:40:57
might try this, not sure it will work (the logic looks kind of dodgey to me) not had chance to test it:

@echo off>outfile & setlocal
set prev=
for /f "tokens=* delims=" %%a in (infile) do (
set line=%%a
call :fixit
)
goto :eof
:fixit
if "%prev%" equ "" goto :xit
set test=%prev:~-1%
if test eq # (
>> outfile echo %prev:~0,-1%,%line%
set prev=
goto :eof
)
set test=%line:~0,1%
if %test% equ [ (
>> outfile echo %prev% %line:~1%
set prev=
goto :eof
)
>> outfile echo %prev%
:xit
set prev=%line%


Report •

Related Solutions

#4
March 14, 2010 at 04:34:45
kennyja:

Excellent specifications of requirements.

Here is a script in biterscripting. I am adding comments.

# Script Replace2.txt
var str file, content
cat $file > $content
#  the first is the combination of a # followed by a return.
# I need to replace this with a ,
while ( { sen "^#\n^" $content } > 0 )
    sal "^#\n^" "," $content > null
# The second pattern is return followed by a [.
# I need to replace this with a space.
while ( { sen "^\n[^" $content } > 0 )
    sal "^\n[^" " " $content > null
# Write $content back to file.
echo $content > { echo $file }

Pass the path to file as argument to the script.

script Replace2.txt file("/path/to/file.csv")

Test on a test file first. The doc for sen (string enumerator) and sal (string alterer) commands is at http://www.biterscripting.com/helpp... .



Report •


Ask Question