You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
Set stream=##class(%FileCharacterStream).%New()
Set stream.Filename="c:\myfile.txt"
While 'stream.AtEnd
{
Set line=stream.ReadLine()
; Process the line here
}
129
Bash Script
Variablen
Wert einer Variable zuweisen
# Aktuelles Verzeichnis in einer Variable setzen
mydir="Mein Verzeichnis lautet $PWD"
echo $mydir
193
Python
Array
Dictionary Basics
# empty dict
myDict = {}
# some static values
myDict ={
"key1" : {"item1":"value1"},
"key2" : {"itemX":"valueY"},
"keyX" : {"item99":"value98"}
}
# update a key programmatically
myDict.update({"key1" = {"item2":"new value"}})
# iterate
for (key, subdict) in myDict.items():
current_key = key
current_subdict = subdict
# get an specific item
subdict = myDict.get("key2")
print subdict.get("itemX")
# valueY
267
PowerShell
Array
Dictionary Basics
# empty Hashtable
$myDict = @{}
# some static values
$myDict.Add("key1", "value1")
$myDict.Add("key2", "valueY")
$myDict.Add("keyX", "value98")
# update a key programmatically
$myDict.Remove("key1")
$myDict.Add("key1", "new value")
# iterate
Foreach ($key in $myDict.keys) {
$strKey = $key
$strValue = $Parameter[$key]
}
# Exists
If ($myDict.ContainsKey("key1") -eq $true) {
write-host "yes"
}
# get an specific item
$subdict = $myDict("key2")
# valueY
76
Python
Netzwerk, Email
Email versenden
# Found at (and little modified): http://www.semi-legitimate.com/sls/blog/37-quick-notes/62-command-line-smtp-from-python
#!/usr/bin/python
import smtplib, sys
if len(sys.argv) != 5:
print "You must call me like:"
print " mailme from to subject msgfile"
sys.exit()
fromadr = sys.argv[1]
toadr = sys.argv[2]
subject = sys.argv[3]
msgfile = sys.argv[4]
try:
f = open(msgfile)
msg = f.read()
except:
print "Invalid Message File: " + msgfile
sys.exit()
m = "From: %s
To: %s
Subject: %s
X-Mailer: My-Mail
" \
% (fromadr, toadr, subject)
smtpserver="mysmtp.lan"
loginuser="Marty_McFly"
loginpwd="DeLorean"
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(loginuser, loginpwd)
smtp.ehlo()
smtp.sendmail(fromadr, toadr, m+msg)
smtp.close()
176
Bash Script
Filehandling
Prüfen ob Datei existiert
# http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#If-Else-Anweisung
#!/bin/bash
filePath="/home/myUser/test.txt"
if [ -f ${filePath} ]
then
echo "There it is! ;-)"
else
echo "Whow, file is missing at this place :-("
fi
174
Bash Script
Strings
Strings miteinander verbinden
# http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#Variablen-abgrenzen
#!/bin/bash
subString1="Hello"
subString2='World!'
echo "${subString1} ${subString2}"
Hello World!
echo "${subString1} ${subString2}. I'm in here ;-)"
# Hello World!. I'm in here ;-)
175
Bash Script
Filehandling
Verzeichnis rekursiv durchsuchen
# http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#Variablen-Teil-2
#!/bin/bash
for file in /home/myUser/*/*.png ; do
echo "Diese Datei: $file"
fname=$(basename "$file")
echo "hat den Namen: $fname"
fdir=$(dirname "$file")
echo "und steht im Verzeichnis: $fdir"
# Diese Datei: /home/myUser/galaxy.png
# hat den Namen: galaxy.png
# und steht im Verzeichnis: /home/myUser
161
Python
Strings
String nach einem Teilstring durchsuchen
# http://www.tutorialspoint.com/python/string_find.htm
# this function is case sensitive
fullstring = "This is my string"
searchFor = "my"
startPosition = fullstring.find(searchFor, 0, len(fullstring))
# startPosition will have 8
if startPosition>=0:
print "I found it!"
startPosition = fullstring.upper().find(searchFor.upper()) # case insensitive