I am writing a script to write to and a sort txt file. After I sort the file I want to add 2 to each line of the file. My script thus far is
#!/bin/bash
cat > /ramdisk/home/stux/unsortedints.out
COUNT=0
FILE =/ramdisk/home/stux/unsortedints.out
for i in {1..100}
do
NUMBER = $[($RANDOM%1000)+1]
echo $NUMBER >> $FILE
done
sort unsortedints.out > sortedints.out
right now nothing happens when I run the script. and im unsure how to add 2, to each of the numbers.
#!/bin/bash
FILE=/ramdisk/home/stux/unsortedints.out
# ^__ There shouldn't be any space here !
: > $FILE # cat unnecessary. Don't repeat the file name
COUNT=0 # Where is it used ?
for i in {1..100}
do
NUMBER=$(( ($RANDOM%1000)+1 ))
# ^_^__ No spaces ! use (( )) for arithmetic expansion
echo $NUMBER >> $FILE
done
sort -n $FILE > sortedints.out
# Use -n to sort on a numeric basis, else 10 wille be before 9
thanks a lot I guess my question now would be how do I traverse through the file to add 2 to each int. I remember reading about a command in awk that did it but cant seem to find it.