Commit 14a9ab58 authored by John Lam's avatar John Lam

problems 1-4

parent 39122785
#!/bin/bash
while read LINE
do
IFS=, read number name color <<< "$LINE"
echo "insert into myfruits (code, name, color) values ($number,\"$name\",\"$color\")"
done < ./sample.txt
if [$1 == ""] 2> /dev/null
then
echo No args
exit
fi
if grep -c "^$1" /etc/passwd > 0;
then
HOME=$(grep "^$1" /etc/passwd | awk -F: ' {print $6}')
echo Home directory: $HOME
else
echo User \""$1"\" not found
fi
# read filenames as arg and print all names in uppercase
for var in "$@"
do
if [ -r $var ]
then
UPPERFILENAME=$(echo $var | tr 'a-z' 'A-Z')
echo $UPPERFILENAME
fi
done
#!/bin/bash
i=1
while [ $i -le 50 ]
do
if [ $(($i % 2)) -eq 1 ]
then
echo Number is : $i
fi
((i++))
done
#!/bin/bash
#declare -A map
total=0
while read LINE
do
IFS=, read start end name email project country billFlag hours<<< "$LINE"
[[ $billFlag == "Y" ]] && total=$(( $total + $hours ))
echo $project $hours
# map[$country]=$hours
done < ./timesheet.csv
echo Total: $total
#for key in "${!map[@]}"; do echo $key; done
###1. Create a script to read a comma delimited file
Read a CSV file containing 3 columns, as shown below and generating an output of SQL statements
File: ./input/sample.txt
```
1,Apple,Color is Red
2,Mango,Color is Orange
3,Banana,Color is Yellow
```
Output file:
```
insert into myfruits (code,name,color) values (1,"Apple","Color is Red")
insert into myfruits (code,name,color) values (2,"Mango","Color is Orange")
insert into myfruits (code,name,color) values (3,"Banana","Color is Yellow")
```
### 2. Parse column
Given a username that exists locally on a linux machine, print home directory of the user. In case the user is not found. It should return an error
hint: list of users and their home directory can be found in /etc/passwd
#### Example 1
```
./myscript.sh root
```
Output:
```
Home directory: /var/root
```
#### Example 2
```
./myscript.sh usernonexists
```
Output:
```
User "usernonexists" not found
```
###3. String Manipulation
Write a shell script that accept one or more file names as argument and prints all names in uppercase, provided they exist in current directory.
Example:
```
myscript.sh $(ls)
```
### 4. Iteration
Print Odd Number between 1 and 50
Output:
```
Number is : 1
Number is : 3
Number is : 5
Number is : 7
Number is : 9
.
.
```
\ No newline at end of file
### 5. Generate Report
Parse sample text file of timesheet users and generate customer will billable hours
Input File: ./bin/timesheet.txt
Output Sample:
```
Customer : Hours
Creative minds : 604.0
Disney Arts : 5494.0
Enterprise solutions : 1530.0
Fake Enterprise : 600.0
Gadget Store : 4332.0
Kids Bank : 10905.5
King Kong carpenter : 680.0
Total : 26777.5
```
1,Apple,Color is Red
2,Mango,Color is Orange
3,Banana,Color is Yellow
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment