Setting a variable to result of FIND command

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Setting a variable to result of FIND command
# 1  
Old 03-09-2005
Setting a variable to result of FIND command

I am working on a batch script where a filter is placed on a directory, and the files that come out of that filter have to be copied into another directory. More specifically, I am trying to set the results of a FIND command to a variable, so that I may access this variable / file later.
The command I have now is:
dir | find "03/07/2005 03:17 PM"|\\ramts11\MarketData\Diag\utils\cut.exe -d " " -f14
The output is in the form of a text file, like:
ccm000000493.txt
I need to store the name of this file in a variable so I can copy it to a different directory. I tried putting
SET /a CCMFile=
in front of the command, but that does not assign CCMFile to anything (the variable CCMFile is still set as null).

Any help would be greatly appreciated.
Thanks a lot,
John Favara
# 2  
Old 03-09-2005
These commands are ms-dos commands. Our users are not Microsoft experts. I'll move this thread to our DOS forum. But even that is really for unix-mircosoft inter-operability issues. You really should post DOS bat file questions on a Microsoft oriented site.
# 3  
Old 03-09-2005
I decided to tackle part of this problem. My quest: write a bat file to set the environment variable x to the output of the "cd" command. I am using the newer cmd.exe on Windows XP rather than the older command.exe. Even so, this was harder than it sounds. My final bat file:
Code:
set x=hello
echo before loop %x%

for /f "usebackq" %%x in (`cd`) do (
      echo in loop x = %%x
      set x=%%x
)

echo after loop %x%

That '/f "usebackq"' option on the "for" statement is the only thing I found that can parse the output of a program. And the variable in the "for" statement seems to not be an environment variable, so I had to do that explicit "set" in the loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Unexplained result of 'find' command

Given this bit of script: retprd=$1 find ${extrnllogdir} -name "*.log" -mtime +$retprd -exec ls -l {} \; >> $logfile produces this (with 'set -x') ++ find /xfers/oracle/dw/data -name '*.log' -mtime +60 -exec ls -l '{}' ';' find: /xfers/oracle/dw/data/cron: Permission denied Where is he... (5 Replies)
Discussion started by: edstevens
5 Replies

3. UNIX for Dummies Questions & Answers

Strange result using find command.

I created a file with the permissions of 776. When I ran the command find /root/Desktop -perm -644 -type f The created file shows up as part of the results. Doesn't -perm -mode mean that for global, only 4(read) and 2(write) can be accepted ? (2 Replies)
Discussion started by: Hijanoqu
2 Replies

4. Shell Programming and Scripting

Assign the result of a multiline command to a variable

Hi, I have the following command that lists all the .o files from all the directories except of vwin (which I don't want it) for i in `ls -d */*.o|awk '$0 !~ "vwin"'`; do echo $i; done The result is something like that dir1/file1.o dir1/file2.o dir2/file3.o etc. So, I want to create a... (9 Replies)
Discussion started by: scor6800
9 Replies

5. Windows & DOS: Issues & Discussions

Read command result as variable

Hi all, Is there a simple way to read a command output as a variable? I've running a batch file to do: attrib.exe * | find /c /v "" >filecount.txt but rather than write it to the txt file I'd like to read the total in as a variable to pass to the rest of the bat file... Any help much... (1 Reply)
Discussion started by: Grueben
1 Replies

6. UNIX for Dummies Questions & Answers

Find command - result order

Hi! Could you please explain why the result order isn't in reverse time order as it is requestet by "xargs ls -ltr" command (ksh shell)? There are about 5000 files in dir. $ find . -name "*201010*" -print |xargs ls -ltr |tail -rw-r--r-- 1 oracle oinstall 54326 Nov 25 20:32... (2 Replies)
Discussion started by: laki47
2 Replies

7. Shell Programming and Scripting

assign awk command result to a variable

#!/bin/sh # ## MYSTRING = `awk '/myApp.app/' /Users/$USER/Library/Preferences/loginwindow.plist` if then echo String not found defaults write /Users/$USER/Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -dict-add -string Hide -bool YES -string Path -string... (9 Replies)
Discussion started by: dedmakar
9 Replies

8. Shell Programming and Scripting

sh : Problem with the result of a find command

Hi I'm working on solaris and I'm trying to run a script. The part listed here does not work properly, the result of the find command is not in the output file /tmp/result (I've checked the find command , executing the shell with sh -x , it seems correct). It seems like I've lost the standard... (4 Replies)
Discussion started by: frenchwill
4 Replies

9. Shell Programming and Scripting

storing result of a command in variable

For whatever reason I cant seem to fix my syntax to do the following. I want to run a grep and count how many instances come up and store that number in a variable but I keep erroring out. Here's my code in bash: number=grep blah file.txt | wc -l (1 Reply)
Discussion started by: eltinator
1 Replies

10. UNIX for Advanced & Expert Users

find command not returning any result

I am looking for all the header files (*.h).. which as per documentation of the UNIX system shouldbe there. I am using find / -name *.h -print But it does't give anything. My question is under what condition the "find" condition will fail to find the file? What is the work around. ... (4 Replies)
Discussion started by: rraajjiibb
4 Replies
Login or Register to Ask a Question