2020年10月8日星期四

bat shell examples1

 if NOT EXIST "project/file.txt" ( 
  ECHO "ERROR: NOT FOUND file.txt, process aborted." 
  GOTO PRC_END 
)

CD project
CALL step2.bat
CD .. 

ECHO "START ant for building..."
C:\eclipse\plugins\org.apache.ant_1.10.5.v20180808-0324\bin\ant make
ECHO "INFO: process completed!"

:PRC_END
EXIT
--------------------------
if EXIST "file.txt" (rm file.txt)
if EXIST "file.zip.old" (
  if EXIST "file.zip" (rm file.zip)
  mv file.zip.old file.zip
)
mv  file.zip  file.gz
gzip -d file.gz
cp file.txt file.txt.bak 

#replace s/pattern/replacement/g
sed -i -e "s/<ns2:user-modules>/<ns2:user-modules\/>\n<ns2:user-modules>/g" file.txt

#replace /startlinepattern/,/endlinepattern/ delete matched lines
sed -i -e "/<ns2:user-modules>/,/<\/ns2:user-modules>/ d" file.txt

#replace s/singlelinepattern//g  delete the matched line.
sed -i -e "s/^\s*<ns2:module id=\"mypackage.*$//g" file.txt
# delete rows between user-module
sed -E -i -e "/<ns2:user-module valid=.+/,/<\/ns2:user-module>/ d" file.txt
# delete rows not match pattern1 and match patter2
sed -E -i -e '/id="jp.co.intra_mart./! {/^\s*<ns2:module id=[^\<\>]+ version=\"1.0.0\"\/>/ d}' file.txt

gzip -k file.txt    #to file.gz and keep file.txt

set time_tmp=%time: =0%
set now=%date:/=%%time_tmp:~0,2%%time_tmp:~3,2%%time_tmp:~6,2%
echo %now%


没有评论: