Börjat på övning 3, labb 4
This commit is contained in:
parent
0c16c0bdd2
commit
6164767b87
30
Labb4/ovning3_ver1.sh
Executable file
30
Labb4/ovning3_ver1.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Jack-Benny Persson
|
||||
# LX13
|
||||
# Övning 3, version1, labb 4
|
||||
# Replace and count words
|
||||
|
||||
# Define some variables
|
||||
File="$1"
|
||||
Old="$2"
|
||||
New="$3"
|
||||
|
||||
# Sanity checks
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage $0 <filename> <old_word> <new_word>"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ! -r $File ]; then
|
||||
echo "We can't read that file"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Main script
|
||||
Data=`cat $1`
|
||||
Alt=${Data/$Old/$New}
|
||||
|
||||
echo "$Alt"
|
||||
|
||||
exit 0
|
2
Labb4/test.txt
Normal file
2
Labb4/test.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Test jag hej
|
||||
Ny rad
|
Loading…
x
Reference in New Issue
Block a user