To get you started, check out the read
builtin:
while read first_word rest_of_the_line; do
... your code here ...
done
You also need a way to feed your input file into that loop.
To get you started, check out the read
builtin:
while read first_word rest_of_the_line; do
... your code here ...
done
You also need a way to feed your input file into that loop.
Parameter expansion will let you carve off parts of a variable.
A few tidbits that should help: when you call a function with a string, the string is split into multiple arguments (the positional parameters, named $n
, where n are integers starting at 1) on the characters in the variable $IFS
(which defaults to spaces, tabs and newlines)
function first() {
echo $1
}
first one two three
# outputs: "one"
$*
and $@
give you all the positional parameters, in order.
Second, the special variable $#
holds the number of arguments to a function.
Third, shift
discards the first positional parameter and moves up all the others by one.
function tail() {
shift
echo $*
}
Fourth, you can capture the output of commands and functions using `...` or $(...)
rest=`tail $*`
Fifth, you can send the output of one command to the input of another using the pipe character (|
):
seq 5 | sort
this is short demo. Go through the words, get the last word and put in front of the string. until the final string is the same as the original.
#!/bin/bash
s="Software Requirements Analysis"
org="$s"
while true
do
last=${s##* } #Analysis
front=${s% *} #Software Requirements
s="$last $front"
echo $s
case "$s" in
"$org") break;;
esac
done
you should be able to do the rest using a file.