views:

87

answers:

4
+2  A: 

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.

Arkku
Thank you very much, I appreciate the help.
Kyle Van Koevering
A: 

Parameter expansion will let you carve off parts of a variable.

Ignacio Vazquez-Abrams
+2  A: 

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
outis
This was very helpful. I've figured out most of the assignment now and simply need to figure out how to store all of these strings in order to sort them alphabetically.
Kyle Van Koevering
@Kyle: see the new hints.
outis
Thanks a lot outis, I really appreciate the help. I like the simplicity of your tail() function.
Kyle Van Koevering
outis
@Kyle: note all the links are to the bash manual, also available at the command line by typing `man bash`. Familiarize yourself with it; it's a great resource for answering questions you have about bash.
outis
A: 

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.

ghostdog74
If I wanted it to remove the first word and append it to the end, what changes would I make to the following two lines?last=${s##* } #Analysisfront=${s% *} #Software RequirementsI don't understand what the s##* and s% * mean.Thank you very much for your answer, it is also very helpful.
Kyle Van Koevering
It isn't spacing my lines correctly in the comment, sorry for it being so messy.
Kyle Van Koevering
see here: http://en.tldp.org/LDP/abs/html/string-manipulation.html under `substring removal` for examples. you should be able to get a feel of how it works and do the necessary yourself.
ghostdog74