Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write OR using pipes and find command in Command Prompt

Status
Not open for further replies.

grofaty

IS-IT--Management
Jan 16, 2003
370
SI
Hi,
on Windows XP SP2 I would like to write a commands using pipes, find and 'or' condition.

Sample file myfile.txt:
Code:
AAA
BBB
CCC

If using command:
type myfile.txt | find "AAA" --> this returs line AAA
type myfile.txt | find "BBB" --> this returs line BBB

How to write command to get both AAA and BBB. I would like to get them in order of appearance in file.

Thanks,
Grofaty
 
Hi, Grofaty

This is a bit clunky, but it works:
Code:
@echo off
type myfile.txt|find /n "BBB" >text.tmp
type myfile.txt|find /n "AAA" >>text.tmp
type myfile.tmp|sort|more
pause
del text.tmp

Jock
 
JockMullin,
thanks a lot. You gave me excellent idea. I have changed it little bit (your code has little bug). So the final code is:
Code:
@echo off
type myfile.txt | find /n "BBB" > temp.txt
type myfile.txt | find /n "AAA" >> temp.txt
type temp.txt | sort > final.txt
type final.txt
del temp.txt
del final.txt
Thanks,
Grofaty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top