--- AWK SED FIND TAR RSYNC EXAMPLES ---
TR
### join all lines in file into one line
cat <file name> | tr -d '\n'
# returns one uniq line in numeric order by UID
sort -n -t: -k3 /etc/passwd
# Removing all undesirable characters at once
# In the shell program we use to remove all non-printable ASCII characters from a text file,
# we tell the tr command to delete every character in the translation process except for the
# specific characters we specify. In essence, we filter out the undesirable characters.
# The tr command we use in our program is shown below:
/usr/bin/tr -cd '\11\12\40-\176' < $INPUT_FILE > $OUTPUT_FILE
### Change all chars from UPPER to lower
tr '[:upper:]' '[:lower:]' < cklist.txt >cklistlc.txt
SORT
sort -n -t: -k3 /etc/passwd ## returns one uniq line in numeric order by UID
AWK
## int vs char
cat non-matching-$1 |awk '$1 ~ /^[0-9]+$/ {print $1" "$2}' |sort -n > uidlist-${1}
cat non-matching-$1 |awk '$1 ~ /^[a-z]/ {print $1" "$2}' |sort -n > usernamelist-${1}
## when the owner does match the name of the dirctory in /u0/users/[A|0-9]
ls -ld $UserName | awk {'if ($3!=$9) print "ls -ld " $3 "; ls -ld " $9}' | sh
cat u0-users-6 | awk {'if ($3!=$9) print $8" "$3 " not "$9}' > u0-users-6.error
### in /u0/users/[0-9}|A
### See UID lable to Dir Name OWNER
ls -l | awk {'if ($3!=$9) print $3 " " $9}'
### When owner doesn't match dir name
ls -l | awk {'if ($3!=$9) print "ls -ld " $9}' |sh
### Check that the owner is in /var/yp/src/passwd
ls -l | awk {'if ($3!=$9) print "grep -w " $9 " /var/yp/src/passwd"}' |sh
ls -l | awk {'if ($3!=$9) print "grep -w " $9 " /var/yp/src/passwd"}' |sh -x
### force the owner name to change
ls -l | awk {'if ($3!=$9) print "chown -f -R " $9" " $9}' |sh
### from a list of UID to USERNAME before move to /u0/NIU/[0-9}|A
cat uid-username.list |awk '{print "grep -w "$2 " /var/yp/src/passwd"}' |sh
cat uid-username.list |awk '{print "mv /u0/user/[insert dir num]/"$2 " /u0/NIU/[insert dir num]/."}
## No UID in /var/yp/src/passwd for a username
cat /var/yp/src/passwd |cut -d: -f1,3 | sed "s/:/ /" | awk {'if ($2=="") print $1 '}
## Join up everyone line into one line in a file
### 1
### 2
### becomes 1 2
awk 'NR%2{printf "%s ",$0;next;}1' FILENAME
awk 'NR%2{printf "%s\t",$0;next;}1' test |sed "s/.binghamton.edu//" |sed "s/.cc//" |sort --key 2
#####################################################################
ls -l | awk {'if ($3!=$9) print $3 " " $9}'
ls -l | awk {'if ($3!=$9) print $3 " " $9}' |sort -n
ls -l | awk {'if ($3!=$9) print $3 " " $9}' |sort -n > /work/NON-MATCHING-UIDS/NON-MATCHING-WHICH-TO-MOVE/non-matching-2
ls -l | awk {'if ($3!=$9) print "grep -w " $9 " /var/yp/src/passwd"}'
ls -l | awk {'if ($3!=$9) print "ls -1 " $9}' |sort |uniq -d
ls -l | awk {'if ($3!=$9) print "ls -ld " $9}' |sh
#################################################################
PERL
perl -pe 'if ($. %2){ chomp }else{ s/^/ = / }' file`
ls -1a |awk '{print "grep -R -w bash "$1}' |tail -n +3 |grep -v rpmbuild |grep -v bash_history |sh -x
ls -1a |egrep -v 'data|BinghamtonUniversity' |awk '{print "du -sh "$1}' | tail -n +3
clear ; /opt/sasinside/sashome/SASFoundation/9.4/utilities/bin/cleanwork -n -hostmatch busas.binghamton.edu /tmp >cleanwork.out 2>&1 ; cat cleanwork.out | grep -v Running |awk -F'[' '{print $2}' |awk -F']' '{print "ps -ef | grep "$1";echo \"#####################################################################################\""}' | sh
SED
sed -i 's/< string to change >/< new string >' /path/to/filename.ext
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i "s/Defaults requiretty/Defaults requiretty\nDefaults:oracle!requiretty/" sudoers### puts new line under the old one
sed -i "s/PREFIX=../PREFIX=22/" ${1}
sed -i "s/NETMASK=255.255.255.0/NETMASK=255.255.252.0/" ${1}
FIND
find . -type f -mtime +8 # Find all files 7 days old in the directory this is run in!
find . -type f -mtime +8 -exec rm -f {} + # ... and delete them.
find . -type f -print | xargs grep -il 128.226.136.115
find . -type f -print | xargs grep -il dbtemplate
find . -type f -print | xargs grep -il 128.226.136.116
find . -type f -print | xargs grep -il apptemplate
RSYNC
SOLARIS
/opt/sfw/bin/rsync -arvzHS --delete -e "/usr/local/openssh/bin/ssh -i /.ssh/doc07" /home/* doc07.cc.binghamton.edu:/home/.
/opt/sfw/bin/rsync -arvzHS --delete -e "/usr/local/openssh/bin/ssh -i /.ssh/doc07" /u0/* doc07.cc.binghamton.edu:/u0/.
Linux
rsync -chaz --verbose /dd-2/Work-BU-Docs/* 128.226.30.236:/root/Desktop/Work-BU-Docs/.
rsync -chaz --verbose /dd-2/www/* 128.226.30.236:/dd-2/www/.
cd /u02; /bin/gtar cpf - * | ssh root@128.226.136.33 "(cd /u02; /bin/tar xpf -)"
cd /u03; /bin/gtar cpf - * | ssh root@128.226.136.33 "(cd /u03; /bin/tar xpf -)"
GTAR TAR - SFTP
dir - ssh - dir tar
cd <dir with content to be tar/mv'd>
/bin/gtar cpf - * | ssh root@###.###.###.### "(cd <dir receive receive content> /bin/tar xpf -)"
For Example
tar cpf - . | ssh casidp2-aws "(cd /usr/local/src; tar xpf - )"
tar cpf - . | ssh root@128.226.1.16 "(cd /home; tar xpf - )"
dir - dir tar
cd /opt-old
tar cvpf - * | ( cd /target; tar xpf -)
cd <to one dir up from dir to be tar/mv'd>
tar cpf - <dir to be mv'd> | ( cd <path to dir receive mv'd dir>; tar xpf -)

``