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%


2020年10月7日星期三

introdction of gzip, tar command

0. unzip:

tar xvzfmp test.tar.gzip -C  /tmp/test/here
m: on error Cannot utime: Operation not permit
p: on error cannot change permit +rmx

1. gzip.

$ ls
docker-compose.yml docker-compose-oracle.yml
$ gzip *.yml 
$ ls 
docker-compose.yml.gz docker-compose-oracle.yml.gz
$ gzip -d *.gz $ ls docker-compose.yml docker-compose-oracle.yml $ gzip -k *.yml $ ls docker-compose.yml.gz docker-compose-oracle.yml.gz docker-compose.yml docker-compose-oracle.yml
$ gzip --help BusyBox v1.31.1 () multi-call binary. Usage: gzip [-cfkdt123456789] [FILE]... Compress FILEs (or stdin) -1..9 Compression level -d Decompress -t Test file integrity -c Write to stdout -f Force -k Keep input files

2. tar 

$ ls
docker-compose.yml docker-compose-oracle.yml
$ tar czf docker-compose.tar.gz *.yml 
$ ls 
docker-compose.yml docker-compose-oracle.yml docker-compose.tar.gz
$ gzip -d *.gz $ ls docker-compose.tar docker-compose.yml docker-compose-oracle.yml $ tar tf docker-compose.tar docker-compose-oracle.yml docker-compose.yml $ tar xf docker-compose.tar $ ls docker-compose.tar docker-compose.yml docker-compose-oracle.yml
$ gzip -k docker-compose.tar $ ls docker-compose.tar docker-compose.tar.gz docker-compose.yml docker-compose-oracle.yml $ rm *.yml $ ls docker-compose.tar docker-compose.tar.gz $ tar xzf docker-compose.tar.gz $ ls docker-compose.tar docker-compose.tar.gz docker-compose.yml docker-compose-oracle.yml

$ tar --help BusyBox v1.31.1 () multi-call binary. Usage: tar c|x|t [-ZzJjahmvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]... Create, extract, or list files from a tar file c Create x Extract t List details -f FILE Name of TARFILE ('-' for stdin/out) -C DIR Change to DIR before operation -v Verbose -O Extract to stdout -m Don't restore mtime -o Don't restore user:group -k Don't replace existing files -Z (De)compress using compress -z (De)compress using gzip -J (De)compress using xz -j (De)compress using bzip2 -a (De)compress using lzma -h Follow symlinks -T FILE File with names to include -X FILE File with glob patterns to exclude --exclude PATTERN Glob pattern to exclude