#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <filename> <number_of_characters>"
exit 1
fi
# Get the filename and number of characters from the arguments
filename=$1
num_chars=$2
# Generate the random letters and save to the file
base_letters=("A" "T" "C" "G")
count=0
> "$filename" # Clear the file if it already exists
for ((i=0; i<num_chars; i++)); do
random_letter=${base_letters[$RANDOM % 4]}
echo -n "$random_letter" >> "$filename"
count=$((count + 1))
if [ $count -eq 50 ]; then
echo "" >> "$filename"
count=0
fi
done
# If the last line is not empty, add a newline at the end of the file
if [ $count -ne 0 ]; then
echo "" >> "$filename"
fi
echo "Generated $num_chars random letters and saved to $filename"
-
Ricardo A Garcia authoredc26edfd5