PC Review


Reply
Thread Tools Rate Thread

How can remove the line match before?

 
 
Blue Fish
Guest
Posts: n/a
 
      4th Sep 2008
Hello:

May I have idea how can I remove the line and one line above if the
char. was matched?

E.G.
Before:
Line 1:<tr>
Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
6.0 </td></tr>
Line 3:<tr>
Line 4:<td>User Name</td><td>user01</td></tr>
Line 5:<tr>
Line 6:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
Line 7:<tr>
Line 8:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>

After: (If the line match "user name" then remove this line and the line
above.
So, Original Line 3 & Line 4 will be removed as below

Line 1:<tr>
Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
6.0 </td></tr>
Line 3:<tr>
Line 4:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
Line 5:<tr>
Line 6:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>

The file sequence many not be the same patten or same line number.

Thanks a lot!
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      4th Sep 2008

"Blue Fish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello:
>
> May I have idea how can I remove the line and one line above if the
> char. was matched?
>
> E.G.
> Before:
> Line 1:<tr>
> Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
> 6.0 </td></tr>
> Line 3:<tr>
> Line 4:<td>User Name</td><td>user01</td></tr>
> Line 5:<tr>
> Line 6:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
> Line 7:<tr>
> Line 8:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
>
> After: (If the line match "user name" then remove this line and the line
> above.
> So, Original Line 3 & Line 4 will be removed as below
>
> Line 1:<tr>
> Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
> 6.0 </td></tr>
> Line 3:<tr>
> Line 4:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
> Line 5:<tr>
> Line 6:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
>
> The file sequence many not be the same patten or same line number.
>
> Thanks a lot!


I am a little confused by your post. Here is what I think you're trying to
say - please confirm:

- I have a text file of the form below.
- I wish to generate a copy of this text file.
- The copy should contain all lines from the original text file,
except the line that contains the string "User Name" and
the line immediately preceding it.
- How would I do this with a batch or a script file?

<tr>
<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release 6.0
</td></tr>
<tr>
<td>User Name</td><td>user01</td></tr>
<tr>
<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
<tr>
<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>


 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      4th Sep 2008

"Blue Fish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello:
>
> May I have idea how can I remove the line and one line above if the
> char. was matched?
>
> E.G.
> Before:
> Line 1:<tr>
> Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
> 6.0 </td></tr>
> Line 3:<tr>
> Line 4:<td>User Name</td><td>user01</td></tr>
> Line 5:<tr>
> Line 6:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
> Line 7:<tr>
> Line 8:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
>
> After: (If the line match "user name" then remove this line and the line
> above.
> So, Original Line 3 & Line 4 will be removed as below
>
> Line 1:<tr>
> Line 2:<td>BIOS Version</td><td>PTLTD - 6040000 PhoenixBIOS 4.0 Release
> 6.0 </td></tr>
> Line 3:<tr>
> Line 4:<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
> Line 5:<tr>
> Line 6:<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
>
> The file sequence many not be the same patten or same line number.
>
> Thanks a lot!



This solution developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]del zout1.txt 2>nul
[3]setlocal
[4]set yst=0
[5]for /f "tokens=1*delims=[]" %%i in ( 'find /n "<td>" ^<zout.txt ') do set
yst=%%i
[6]if %yst%==0 echo string not found&goto :eof
[7]set /a yft=%yst% - 1
[8]for /f "tokens=1*delims=[]" %%i in ( 'find /v /n "" ^<zout.txt ') do if
not %%i==%yft% if not %%i==%yst% >>zout1.txt echo\%%j
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof

*Will NOT work properly for lines beginning with "[" or "]"

ZOUT.txt is the source file, ZOUT1.txt is the destination file; select the
string to find in [5] appropriately.




 
Reply With Quote
 
Blue Fish
Guest
Posts: n/a
 
      4th Sep 2008
Hello:

Sorry for my English was not enough. Let me try to explain as much as I can.

I have a html file which is a text base.
The file contain like as follow:

*** parts of the html file ***
<tr>
<td>BIOS Version</td><td>PhoenixBIOS 4.0 Release 6.0 </td></tr>
<tr>
<td>User Name</td><td>user01</td></tr>
<tr>
<td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
<tr>
<td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
*** parts of the html file ***


It was a HTML code of <tr></tr> I need to remove it in pair. From the
about, I need to remove the line with "User Name". So, I need to remove
the line contain with "User Name" and together with the above line of
<tr> as it was a pair. Is it possible to do that?

Thanks!
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      4th Sep 2008

"Blue Fish" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hello:
>
> Sorry for my English was not enough. Let me try to explain as much as I
> can.
>
> I have a html file which is a text base.
> The file contain like as follow:
>
> *** parts of the html file ***
> <tr>
> <td>BIOS Version</td><td>PhoenixBIOS 4.0 Release 6.0 </td></tr>
> <tr>
> <td>User Name</td><td>user01</td></tr>
> <tr>
> <td>System Uptime</td><td>11 Days, 17 Hours, 55 Minutes</td></tr>
> <tr>
> <td>Local Time</td><td>2008-08-07 16:48:47</td></tr>
> *** parts of the html file ***
>
>
> It was a HTML code of <tr></tr> I need to remove it in pair. From the
> about, I need to remove the line with "User Name". So, I need to remove
> the line contain with "User Name" and together with the above line of
> <tr> as it was a pair. Is it possible to do that?
>
> Thanks!


Did you try the solution proposed by "billious"?


 
Reply With Quote
 
Timo Salmi
Guest
Posts: n/a
 
      4th Sep 2008
Blue Fish <(E-Mail Removed)> wrote:
> May I have idea how can I remove the line and one line above if the
> char. was matched?


You might wish to study and run the following example code
@echo off & setlocal enableextensions
::
:: Make a test file
set testfile=C:\_M\MyTest.txt
for %%f in ("%testfile%") do if exist %%f del %%f
for /L %%i in (1,1,3) do echo This is row 0%%i>>"%testfile%"
echo.>>"%testfile%"
for /L %%i in (5,1,9) do echo This is row 0%%i>>"%testfile%"
rem type "%testfile%"
::
set targetString=row 07
::
:: Get the line number of the target string
for /f "tokens=1 delims=:" %%a in ('
findstr /n /c:"%targetString%" "%testfile%"') do (
set lineNber=%%a)
::
set /a n1=%lineNber%-2
sed -n 1,%n1%p "%testfile%"
set /a n2=%lineNber%+1
sed -n %n2%,$p "%testfile%"
::
for %%f in ("%testfile%") do if exist %%f del %%f
endlocal & goto :EOF

The test file is
This is row 01
This is row 02
This is row 03

This is row 05
This is row 06
This is row 07
This is row 08
This is row 09

The output is
This is row 01
This is row 02
This is row 03

This is row 05
This is row 08
This is row 09

The solution avoids the empty line catch common in pure batches.

For more information and alternatives see e.g.
23} How do I get the n'th, the first and the last line of a text file?
file:///C:/_G/WWW/~NETIKKA/SALMTI02/INFO/tscmd023.htm

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
private.php?do=newpm&u= <http://www.uwasa.fi/~ts/> ; FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
 
Reply With Quote
 
Timo Salmi
Guest
Posts: n/a
 
      4th Sep 2008
Timo Salmi <(E-Mail Removed)> wrote:
> For more information and alternatives see e.g.
> 23} How do I get the n'th, the first and the last line of a text file?
> file:///C:/_G/WWW/~NETIKKA/SALMTI02/INFO/tscmd023.htm


http://www.netikka.net/tsneti/info/tscmd023.htm

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
private.php?do=newpm&u= <http://www.uwasa.fi/~ts/> ; FI-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
 
Reply With Quote
 
Blue Fish
Guest
Posts: n/a
 
      5th Sep 2008
May I know where I can have the "sed" command?

Thanks!
 
Reply With Quote
 
Blue Fish
Guest
Posts: n/a
 
      5th Sep 2008
Yes I have try but it didn't work. I didn't know where I can input the
target for searching the keyword. It was because beside of "User Name" I
also need to filter the others.

Thanks!

Pegasus (MVP) wrote:
> Did you try the solution proposed by "billious"?
>
>
>

 
Reply With Quote
 
billious
Guest
Posts: n/a
 
      5th Sep 2008

"Blue Fish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Pegasus (MVP) wrote:
>> Did you try the solution proposed by "billious"?
>>
>>

>


> Yes I have try but it didn't work. I didn't know where I can input the
> target for searching the keyword. It was because beside of "User Name" I
> also need to filter the others.
>
> Thanks!
>


The string to be found is the string in quotes following the "find" keyword
in [5] - I was looking for "<td>" in testing.

Replace "<td>" in [5] with "User Name"

Add /i after the /n to make the search case-insensitive (ie. use

FIND /n /i

instead of

FIND /n

)

OR

replace <td> in [5] with %~1

You could then run your batch as

BATCHNAME "User Name"
or
BATCHNAME Something

to search for "User Name" or "Something" (If there are spaces in your target
string, enclose in quotes)

Or do you want to wait for user-input to get your target string?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line/Script to Remove/Uninstall Program that can only be removed from Add or Remove Programs Conan Kelly Windows XP General 2 15th May 2010 12:18 AM
Re: draw line on a form/panel and remove/clear the line? rowe_newsgroups Microsoft VB .NET 0 18th Jan 2007 02:51 AM
Re: draw line on a form/panel and remove/clear the line? Ray Cassick Microsoft VB .NET 0 18th Jan 2007 12:10 AM
remove dashed line under address line in word document =?Utf-8?B?anVzdGxlYXJuaW5n?= Microsoft Word Document Management 10 21st Mar 2006 08:56 PM
How do I remove repeating line in Excell - Top line on each page.. =?Utf-8?B?a2VlcG9u?= Microsoft Excel Worksheet Functions 1 23rd Mar 2005 11:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 AM.