Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
Hi there.
i have created a program that in the end it will give output like this
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
.............. 17
i wonder how to save the output into a single string and into a file.
i.e 1 10 11 12 9 2 3 8 13 14 7 4 5 6 15 17 (in this order, its like a snake)
i googled it but i only came across with saving it row by row (1 2 3 4 5 10 9......)
any idea how?
- Relevant commands, code, scripts, algorithms:
file4="temp.txt"
name4=$(cat $file4)
echo $name4 | sed 's/\(.\)/\1\n/g' > file4.txt
echo "enter how many rows :"
read cols
IFS=$'\n' a=($(cat file4.txt))
for j in $(seq ${#a[*]}); do
[[ ${a[$j-1]} = $name ]] && echo "${a[$i]}"
done
for (( i=0; i<=$(( ${#a[@]} / cols )); ++i )); do
for (( j=0; j<cols; ++j )); do
if (( i%2 )); then idx=$(( (i + 1) / 2 * 2 * cols - j - 1 ))
else idx=$(( (i / 2) * 2 * cols + j )); fi
printf "%-4s " "${a[idx]}"
done
printf "\n"
done
-
The attempts at a solution (include all code and scripts):
-
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).