add things resources from the last 5 years over machines

This commit is contained in:
autistic-symposium-helpers 2024-10-15 09:59:09 +09:00 committed by GitHub
parent ac9c955e0b
commit b0a4e417ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
77 changed files with 2327 additions and 84 deletions

59
awk/AWK_TIPS.md Normal file
View file

@ -0,0 +1,59 @@
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
}
```

41
awk/TIPS.txt Normal file
View 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

View 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
awk/for_loop.awk Normal file
View 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
awk/math1.awk Normal file
View file

@ -0,0 +1,8 @@
# awk -f math1
{
no1 = $1
no2 = $2
ans = $1 + $2
print no1 " + " no2 " = " ans
}

30
awk/math2.awk Normal file
View 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"]
}