Need help with a simple srcipt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dtalex
Posts: 2
Joined: 29 Sep 2011 13:03

Need help with a simple srcipt

#1 Post by dtalex » 29 Sep 2011 13:09

Hi all
can you please help me converting thi simple script from bash to batch?

Code: Select all

for element in `ls | grep .sql` 
do
   cat $element >> scriptino.sql
done


I just want to put the output of all .sql files in a directory
in anoither sql file in the same directory

Thank you

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Need help with a simple srcipt

#2 Post by dbenham » 29 Sep 2011 13:54

Everything below assumes you are running the command or script from the directory with the .sql files, as does your script.

From the command line:

Code: Select all

(for %f in (*.sql) do type "%f")>scripino.sql

Within a script (.bat or .cmd file)

Code: Select all

(for %%f in (*.sql) do type "%%f")>scripino.sql


Both the above will include the TYPE command with filename above each file contents. If you only want the file contents then we need to disable the echoing of the command:

from command line:

Code: Select all

(for %f in (*.sql) do @type "%f")>scripino.sql

Within a script:

Code: Select all

@echo off
(for %%f in (*.sql) do type "%%f")>scripino.sql


Dave Benham

dtalex
Posts: 2
Joined: 29 Sep 2011 13:03

Re: Need help with a simple srcipt

#3 Post by dtalex » 29 Sep 2011 14:37

Thank you Dave

dbenham wrote:Everything below assumes you are running the command or script from the directory with the .sql files, as does your script.


What I want to to is just double click on it (already placed in the directory i'm intrested) and run the output file in sql developer ('/' are already included in sql files)

Post Reply