This returns the line number and removes the string. Now that I have the line number I want to subtract 4 from it and give me a new line number.
newlinenumber=$((linenumber - 4))
What I would like to do is find the line number and subtract by 4 BEFORE storing to the variable "linenumber" so I can avoid creating a new variable "newlinenumber" altogether. Essentially I want to combine the two with the idea pictured as follows:
(and assuming that the cut -fi was a typo and you meant
cut -f1[/ICODE)], you could use:
linenumber=$(grep -n "string" $FILENAME | cut -d : -f1)
linenumber=$((linenumber - 4))
and, you can get rid of the cut completely with: linenumber=$(grep -n "string" $FILENAME)) linenumber=${linenumber%%:*} linenumber=$((linenumber - 4)) which also keeps you from getting a syntax error if more than one line in your file contains "string" (in which case this will set linenumber to the number of the 1st line in the file containing "string" minus four). And, this could also be written as: