02-18-2011
I know that, the sample of code I posted was copied from the interactive command-line, hence single-% denoted variables. I've been reading the help file for "for /?" and it's pretty worthless and borderline esoteric!
I'm not certain whether my DEVE is working correctly.
Thanks for your suggestion though.
---------- Post updated at 08:04 PM ---------- Previous update was at 06:53 PM ----------
I'm not sure what worked so differently for me this time, but I was able to successfully execute the code above as intended using the following syntax. This is for your reference.
at the interactive command-line, you'll use single-%-denoted iteration variables, but in a batch script, you'll use double-%-denoted variables for the iteration statements/command sets. I'll demonstrate batch-script form, italicized commentary is FYI, the bold-print characters are the actual script commands.
SETLOCAL ENABLEDELAYEDEXPANSION
this line turns on delayed environment variable expansion, necessary to store and expand variables set within the for loop. Otherwise, variable values are expanded as the command is parsed (before execution)
for /f "usebackq" %%A in (`dir /b C:\directory\`) do (
this first line is using %%A as the iterator variable, storing each line of output from dir /b (the b option is equivalent to ls -1 in UNIX)
set origname=%%A
stores the value of %%A into a variable (origname) that can be manipulated later in the loop iteration
set eighth=!origname:~7,1!
this stores the eighth character of origname variable, the variable must now be expanded using exclamation points for flags instead of percent-symbols. But is still subject to all the rules of regullar command-shell variables, including string manipulation.
if !eighth!==3 (
begin if condition
move /Y C:\directory\!origname! C:\directory\output\!origname:~0,7!5!origname:~8,6!
based on result of if comparison, moves original file to a parsing directory for a program that uses 8th character to process based on a rule set, as you can (or cannot) tell--the original filename is expected to be a 14-character string and we're modifying the 8th character to conform to a ruleset for processing) else (
move /Y C:\directory\!origname! C:\directory\output\!origname:~0,7!3!origname:~8,6!
)
)
The else condition is a coverall for files that do conform to a ruleset but erred for one reason or another and thus processes them using a different ruleset.
Hopefully this makes sense to you. Initially, when the command-line was expanding the variables, it was printing some funky stuff. It seemed to just start working, but who knows--I've been staring at this damm screen so long.
ProGrammar
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi everyone,
I am trying to set up the .profile for a user I have just created. In trying to set up the shell variables, I want to make the shell be korn shell (default shell i believe is Borne shell), so, this is what I did:
SHELL=/usr/bin/ksh
export SHELL
Whenl executing the .profile,... (1 Reply)
Discussion started by: rachael
1 Replies
2. Shell Programming and Scripting
If I set a variable within a while-read loop, sometimes it's local to the loop, sometimes it's global, depending on how the loop is set up. I'm testing this on a Debian Lenny system using both bash and dash with the same results.
For example:
# Pipe command into while-read loop
count=
ls -1... (2 Replies)
Discussion started by: mjd_tech
2 Replies
3. UNIX for Dummies Questions & Answers
Hi All
How can i control for loop with two different variables in csh shell
Regards
Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies
4. UNIX for Dummies Questions & Answers
I nedd help on the below highlited one.
can any one explain on this,How its work in shell scripting.. then that will be very great full...
L_ABCD=${L_DBG:=N}
Thanks
Muddasas (3 Replies)
Discussion started by: muddasani
3 Replies
5. Shell Programming and Scripting
Hi,
does anybody knows how to manage, that the filenames are assigned to a variable in a loop afer getting them with set command in a ksh, like:
set B*.txt
i=1
c=$#
x=$((c+1))
echo "$x"
while ] ; do
_ftpfile$i="$"$i
echo "$_ftpfile$i"
i=$((i+1))
done
The first echo returns,... (2 Replies)
Discussion started by: spidermike
2 Replies
6. UNIX for Dummies Questions & Answers
Hello,
I have two files File1 & File2.
File1
76 135
136 200
250 345
....
File2
1 24
1 35
1 36
1 72
....
I want to get all the values form File2 corresponding to the range in File 1 and feed it to a program. Is the code below right? Can I pass shell variables to awk in this... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies
7. Shell Programming and Scripting
Hi,
I am having a bit of trouble with the below code:
file=/path/to/file
for i in 03 06 07 21; do
if ; then
eval count$i=`grep -c word $file-$i`
fi
done
Totalcount=0
for i in 03 06 07 21; do
if ; then
echo $count$i variable not exist;
else Tcount=`expr $Tcount + $count$i`;
fi... (3 Replies)
Discussion started by: brunlea
3 Replies
8. Shell Programming and Scripting
Well,
this command has served me quite well under DOS
for %%X in (*.txt) do COMMAND
however in linux it just outputs:
"./install.sh line 1: '%%x': not a valid identifier.
Ideas ?
Thanks in advance (2 Replies)
Discussion started by: pasc
2 Replies
9. Shell Programming and Scripting
Hello All.
Good Afternoon.
I need one small help regarding setting of env variables for a particular host by getting it from the DB.
For ex :
1. I am using LOCALHOST.
2. When I run a ./hostset.sh it should pick up the Oracle home details from associated DB and set it.
Please... (1 Reply)
Discussion started by: PavanPatil
1 Replies
10. Shell Programming and Scripting
Hi guys!
Kind of new to bash scripting and now I'm stuck.
I need to curl with these variables:
"{ \"nodename\": \"$1\", \"ipaddress\": \"$2\", \"poolname\": \"$3\", \"port\": \"$4\", \"loadbalancer\" : \"$5\" }"
and my input_file.txt contains
server001 10.10.10.01 serverpool1 80... (4 Replies)
Discussion started by: yort
4 Replies
LEARN ABOUT DEBIAN
data::dumpxml
DumpXML(3pm) User Contributed Perl Documentation DumpXML(3pm)
NAME
Data::DumpXML - Dump arbitrary data structures as XML
SYNOPSIS
use Data::DumpXML qw(dump_xml);
$xml = dump_xml(@list)
DESCRIPTION
This module provides a single function called dump_xml() that takes a list of Perl values as its argument and produces a string as its
result. The string returned is an XML document that represents any Perl data structures passed to the function. Reference loops are han-
dled correctly.
The following data model is used:
data : scalar*
scalar = undef | str | ref | alias
ref : scalar | array | hash | glob | code
array: scalar*
hash: (key scalar)*
The distribution comes with an XML schema and a DTD that more formally describe this structure.
As an example of the XML documents produced, the following call:
$a = bless [1,2], "Foo";
dump_xml($a);
produces:
<?xml version="1.0" encoding="US-ASCII"?>
<data xmlns="http://www.cpan.org/.../Data-DumpXML.xsd">
<ref>
<array class="Foo">
<str>1</str>
<str>2</str>
</array>
</ref>
</data>
If dump_xml() is called in a void context, then the dump is printed on STDERR automatically. For compatibility with "Data::Dump", there is
also an alias for dump_xml() called simply dump().
"Data::DumpXML::Parser" is a class that can restore data structures dumped by dump_xml().
Configuration variables
The generated XML is influenced by a set of configuration variables. If you modify them, then it is a good idea to localize the effect.
For example:
sub my_dump_xml {
local $Data::DumpXML::INDENT = "";
local $Data::DumpXML::XML_DECL = 0;
local $Data::DumpXML::DTD_LOCATION = "";
local $Data::DumpXML::NS_PREFIX = "dumpxml";
return dump_xml(@_);
}
The variables are:
$Data::DumpXML::INDENT
You can set the variable $Data::DumpXML::INDENT to control the amount of indenting. The variable contains the whitespace you want to
be used for each level of indenting. The default is a single space. To suppress indenting, set it to "".
$Data::DumpXML::INDENT_STYLE
This variable controls where end element are placed. If you set this variable to the value "Lisp" then end tags are not prefixed by
NL. This give a more compact output.
$Data::DumpXML::XML_DECL
This boolean variable controls whether an XML declaration should be prefixed to the output. The XML declaration is the <?xml ...?>
thingy. The default is 1. Set this value to 0 to suppress the declaration.
$Data::DumpXML::NAMESPACE
This variable contains the namespace used for the XML elements. The default is to let this be a URI that actually resolve to the XML
schema on CPAN. Set it to "" to disable use of namespaces.
$Data::DumpXML::NS_PREFIX
This variable contains the namespace prefix to use on the elements. The default is "", which means that a default namespace will be
declared.
$Data::DumpXML::SCHEMA_LOCATION
This variable contains the location of the XML schema. If this variable is non-empty, then an "xsi:schemaLocation" attribute is added
to the top level "data" element. The default is not to include this, as the location can be inferred from the default XML namespace
used.
$Data::DumpXML::DTD_LOCATION
This variable contains the location of the DTD. If this variable is non-empty, then a <!DOCTYPE ...> is included in the output. The
default is to point to the DTD on CPAN. Set it to "" to suppress the <!DOCTYPE ...> line.
BUGS
Class names with 8-bit characters are dumped as Latin-1, but converted to UTF-8 when restored by the Data::DumpXML::Parser.
The content of globs and subroutines are not dumped. They are restored as the strings "** glob **" and "** code **".
LVALUE and IO objects are not dumped at all. They simply disappear from the restored data structure.
SEE ALSO
Data::DumpXML::Parser, XML::Parser, XML::Dumper, Data::Dump
AUTHORS
The "Data::DumpXML" module is written by Gisle Aas <gisle@aas.no>, based on "Data::Dump".
The "Data::Dump" module was written by Gisle Aas, based on "Data::Dumper" by Gurusamy Sarathy <gsar@umich.edu>.
Copyright 1998-2003 Gisle Aas.
Copyright 1996-1998 Gurusamy Sarathy.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.8.8 2006-04-08 DumpXML(3pm)