I have a bash script where I'm using a for loop to generate a list of numbers (increasing by one).
Within my loop I use echo in combination with tee to build out my string.
I then use sed to take my "list" (input as file) of numbers and then format it.
Since I use a for loop to generate this list (text file), is there a better and more efficient way for me to create my string (it's being appended as it's being looped) to include values double quoted without having to write to a file first?
Here's my code:
#!/usr/local/bin/bash
if [[ $# != 3 ]]; then
echo "Usage: ./crIPRange.sh <octet> <start#> <ending#>" 2>&1
echo "Example: ./crIPRange.sh 10.1.2 100 150" 2>&1
exit 1
fi
_octet="$1"
_startIP="$2"
_IPList="List1.out"
_IPListFinal="List2.out"
for (( c=$2; c<=$3; c++ ))
do
echo "${_octet}.$c" | tee >> ${_IPList}
sed -E 's/^(.*)$/"\1"/' ${_IPList} | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/,/g' | tee > ${_IPListFinal}
done
In other words, I'm thinking I don't necessarily need that step of writing it to a file as a list?
So in the end, I have (2) output files and I really just need my final output. Would I use something like printf?