Hi. I have a sample excel sheet with 3 (or more) columns below:
cat1 kitty black
cat2 furry yellow
cat3 missy black
dog1 baxter white
dog2 ellon red
fish1 gold yellow
fish2 fin red
I need a command/script/batch file that queries from a certain column (say 1st column), then displays the result from selected columns only (say 1st and 2nd).
Example:
command: findpet.bat dog
result:
dog1 baxter
dog2 ellon
i only need the results to be displayed on the console. thanks!
Command query on excel file
Moderator: DosItHelp
Re: Command query on excel file
.BAT file cannot read excel files. You would need to use Vbscript or Powershell to do such a task.
If your file was a text file that was delimited by a specified delimiter then it should be fairly easy to do with a .BAT file.
If your file was a text file that was delimited by a specified delimiter then it should be fairly easy to do with a .BAT file.
Re: Command query on excel file
Yes, i can convert the Excel sheet to a delimited text file.
If you have a sample bat i can work with, that would be great. Thanks!
If you have a sample bat i can work with, that would be great. Thanks!
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Command query on excel file
Code: Select all
@echo off
if "%~1"=="" exit /b
set "source_file=data.csv"
for /f "tokens=1,2 delims= " %%A in ('findstr /C:"%~1" %source_file%') do echo %%A %%B
- Your source file is called data.csv
- Your data is separated by spaces (despite the C in CSV standing for "comma")
- You're fine with hardcoding the data filename
Re: Command query on excel file
ShadowThief, It would be safer to perform your search against the content of the target field, not over the entire data record. What happens if, the fish is a catfish, or dogfish? the dog is named Catlin? or the color of the cat is dogs liver?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Command query on excel file
I put in as much effort as ibirp put into their question