mirror of
https://github.com/autistic-symposium/shell-whiz-toolkit.git
synced 2025-05-12 11:42:20 -04:00
some sytem scripts
This commit is contained in:
parent
4b0a965e4a
commit
5852171b21
25 changed files with 639 additions and 1 deletions
53
shell_scripts/power_user_awk/AWK_TIPS.txt
Normal file
53
shell_scripts/power_user_awk/AWK_TIPS.txt
Normal file
|
@ -0,0 +1,53 @@
|
|||
Data Manipulation
|
||||
-----------------
|
||||
|
||||
|
||||
Print elements in the column 3 that has the word "good" in the other columns
|
||||
$ awk '/good/ { print $3 }' inventory
|
||||
|
||||
Syntax:
|
||||
$ awk -f {PROGRAM FILE} FILENAME
|
||||
|
||||
awk program is:
|
||||
|
||||
PATTERN{
|
||||
ACTION 1
|
||||
ACTION 2
|
||||
ACTION 3
|
||||
}
|
||||
|
||||
|
||||
. (Dot) Match any character
|
||||
* Match zero or more character
|
||||
^ Match beginning of line
|
||||
$ Match end of line
|
||||
\ Escape character following
|
||||
[ ] List
|
||||
{ } Match range of instance
|
||||
+ Match one more preceding
|
||||
? Match zero or one preceding
|
||||
| Separate choices to match
|
||||
|
||||
|
||||
|
||||
IF CONDITION
|
||||
------------
|
||||
|
||||
if (condition)
|
||||
{
|
||||
Statement 1
|
||||
Statement 2
|
||||
Statement N
|
||||
if condition is TRUE
|
||||
}
|
||||
else
|
||||
{
|
||||
Statement 1
|
||||
Statement 2
|
||||
Statement N
|
||||
if condition is FALSE
|
||||
}
|
||||
|
||||
|
||||
FOR LOOP
|
||||
--------
|
41
shell_scripts/power_user_awk/TIPS.txt
Normal file
41
shell_scripts/power_user_awk/TIPS.txt
Normal file
|
@ -0,0 +1,41 @@
|
|||
For files with many columns:
|
||||
===========================
|
||||
|
||||
$ cut -f2 NAMEFILE --> display the second column
|
||||
$ cut -f1 NAMEFILE --> display first column
|
||||
$ paste FILE1 FILE2 --> join the columns together of two files
|
||||
$ join FILE1 FILES2 --> join separate files but only if there is common field in both files with identical values
|
||||
|
||||
|
||||
Changing the contend of files:
|
||||
==============================
|
||||
|
||||
CHARACTERS:
|
||||
----------
|
||||
|
||||
$ tr "h2" "3x" < FILENAME --> changes all h to 3 and all 2 to x
|
||||
|
||||
|
||||
WORDS:
|
||||
------
|
||||
$ sed expression file
|
||||
$ sed '/tea/s//milk/g' FILENAME
|
||||
|
||||
/tea/ --> find tea word
|
||||
s//milk/ --> replace (substitute) the word milk for tea
|
||||
g --> make the changes globally
|
||||
|
||||
|
||||
DUPLICATES:
|
||||
-----------
|
||||
|
||||
Print LINES that are unique.
|
||||
$ uniq FILENAME
|
||||
|
||||
Duplicate lines must be next to next to each other, so it's better to sort first:
|
||||
$ sort FILENAME | uniq
|
||||
|
||||
|
||||
Ex
|
||||
--
|
||||
$ ex FILENAME --> start the editor
|
21
shell_scripts/power_user_awk/file_directory_example.awk
Normal file
21
shell_scripts/power_user_awk/file_directory_example.awk
Normal file
|
@ -0,0 +1,21 @@
|
|||
# awk -f FILEAWK FILELIST
|
||||
|
||||
BEGIN{
|
||||
}
|
||||
|
||||
#
|
||||
# main logic is here
|
||||
#
|
||||
{
|
||||
sfile = $1
|
||||
dfile = $2
|
||||
cpcmd = "cp " $1 " " $2
|
||||
printf "Coping %s to %s\n",sfile,dfile
|
||||
system(cpcmd)
|
||||
}
|
||||
|
||||
#
|
||||
# End action, if any, e.g. clean ups
|
||||
#
|
||||
END{
|
||||
}
|
12
shell_scripts/power_user_awk/for_loop.awk
Normal file
12
shell_scripts/power_user_awk/for_loop.awk
Normal file
|
@ -0,0 +1,12 @@
|
|||
# awk -f for_loop.awk
|
||||
|
||||
BEGIN {
|
||||
printf "To test for loop\n"
|
||||
printf "Press CTRL + C to stop\n"
|
||||
}
|
||||
{
|
||||
for(i=0;i<NF;i++)
|
||||
{
|
||||
printf "Welcome %s, %d times.\n" ,ENVIRON["USER"], i
|
||||
}
|
||||
}
|
8
shell_scripts/power_user_awk/math1.awk
Normal file
8
shell_scripts/power_user_awk/math1.awk
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
# awk -f math1
|
||||
{
|
||||
no1 = $1
|
||||
no2 = $2
|
||||
ans = $1 + $2
|
||||
print no1 " + " no2 " = " ans
|
||||
}
|
30
shell_scripts/power_user_awk/math2.awk
Normal file
30
shell_scripts/power_user_awk/math2.awk
Normal file
|
@ -0,0 +1,30 @@
|
|||
# awk -f math2
|
||||
|
||||
BEGIN {
|
||||
myprompt = "(To Stop press CTRL+D) > "
|
||||
printf "Welcome to MyAddtion calculation awk program v0.1\n"
|
||||
printf "%s" ,myprompt
|
||||
}
|
||||
|
||||
{
|
||||
no1 = $1
|
||||
op = $2
|
||||
no2 = $3
|
||||
ans = 0
|
||||
|
||||
if ( op == "+" )
|
||||
{
|
||||
ans = $1 + $3
|
||||
printf "%d %c %d = %d\n" ,no1,op,no2,ans
|
||||
printf "%s" ,myprompt
|
||||
}
|
||||
else
|
||||
{
|
||||
printf "Opps!Error I only know how to add.\nSyntax: number1 + number2\n"
|
||||
printf "%s" ,myprompt
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
printf "\nGoodbye, %s\n !" , ENVIRON["USER"]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue