Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bash-assigments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex Segers
bash-assigments
Commits
7975b5c2
Commit
7975b5c2
authored
Mar 29, 2021
by
Alex Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
README.md and generate-readme.sh
parent
a418da43
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
0 deletions
+110
-0
README.md
README.md
+86
-0
generate-readme.sh
generate-readme.sh
+24
-0
No files found.
README.md
0 → 100644
View file @
7975b5c2
# Bash Scripting SOLUTIONS [@asegers]
Run
`generate-readme.sh`
to parse solutions here
## Q: [1-generate-sql](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/1-generate-sql.md)
```
bash
#!/bin/bash
SAMPLE_TXT
=
"../input/sample.txt"
while
read
-r
ROW
||
[
-n
"
$ROW
"
]
;
do
CODE
=
$(
echo
$ROW
|
awk
-F
,
'{ print $1 }'
)
NAME
=
$(
echo
$ROW
|
awk
-F
,
'{ print $2 }'
)
COLOR
=
$(
echo
$ROW
|
awk
-F
,
'{ print $3 }'
)
echo
"insert into myfruits (code, name, color) values (
$CODE
,
\"
$NAME
\"
,
\"
$COLOR
\"
)"
done
<
$SAMPLE_TXT
```
## Q: [2-parse-columns](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/2-parse-columns.md)
```
bash
#!/bin/bash
PASSWD_FILE
=
"/etc/passwd"
SEARCH_USER
=
$1
while
read
-r
ROW
||
[
-n
"
$ROW
"
]
;
do
USER
=
$(
echo
$ROW
|
awk
-F
:
'{ print $1 }'
)
if
[[
$USER
==
$SEARCH_USER
]]
then
HOME_DIR
=
$(
echo
$ROW
|
awk
-F
:
'{ print $6 }'
)
echo
"Home directory:
$HOME_DIR
"
exit
0
fi
done
<
$PASSWD_FILE
echo
"User
\"
$SEARCH_USER
\"
not found"
exit
1
```
## Q: [3-string-manipulation](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/3-string-manipulation.md)
```
bash
#!/bin/bash
for
FILE_NAME
in
"
$@
"
do
if
[[
-f
"
$FILE_NAME
"
]]
then
echo
"
$FILE_NAME
"
|
awk
'{ print toupper($0) }'
else
echo
"File "
\"
$FILE_NAME
\"
" does not exist in this directory"
fi
done
```
## Q: [4-iteration](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/4-iteration.md)
```
bash
#!/bin/bash
for
N
in
$(
seq
50
)
do
if
[[
$(
expr
$N
% 2
)
-ne
0
]]
then
echo
"Number is :
$N
"
fi
done
```
## Q: [5-generate-report](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/5-generate-report.md)
```
bash
#!/bin/bash
TIMESHEET_CSV
=
"../input/timesheet.csv"
echo
"Customer : Hours"
awk
-F
,
'$7 == "Y" {
arr[$5] += $8
} END {
for(CUSTOMER in arr)
printf "%s : %.1f\n", CUSTOMER, arr[CUSTOMER]
}'
<
$TIMESHEET_CSV
```
generate-readme.sh
0 → 100644
View file @
7975b5c2
#!/bin/bash
[
-e
README.md
]
&&
rm
README.md
touch
README.md
FILES
=
"solutions/*.sh"
echo
"# Bash Scripting SOLUTIONS [@asegers]"
>>
README.md
echo
""
>>
README.md
echo
"Run
\`
generate-readme.sh
\`
to parse solutions here."
>>
README.md
for
FILE
in
$FILES
do
BASE
=
$(
basename
-s
.sh
$FILE
)
Q_URL
=
"## Q: [
$BASE
](https://gitlab.mynisum.com/devops/devops-foundation/blob/master/bash-scripting/questions/
$BASE
.md)"
echo
""
>>
README.md
echo
$Q_URL
>>
README.md
echo
"
\`\`\`
bash"
>>
README.md
cat
$FILE
>>
README.md
echo
""
>>
README.md
echo
"
\`\`\`
"
>>
README.md
done
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment