Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
837 B
3
Indexable
#!/bin/bash

# Kiểm tra xem người dùng đã nhập tên tệp đầu vào hay chưa
if [ "$#" -ne 1 ]; then
  echo "Sử dụng: $0 <tên tệp danh sách>"
  exit 1
fi

input_file="$1"
output_file="subplan.txt"
output_file2="subplan2.txt"

# Kiểm tra xem tệp testcaselist.txt tồn tại
if [ ! -f "$input_file" ]; then
  echo "Tệp $input_file không tồn tại."
  exit 1
fi

# Chọn tên tệp kết quả dựa trên sự tồn tại của subplan.txt
if [ -f "$output_file" ]; then
  output_file="$output_file2"
fi

# Xóa mọi dấu cách từng dòng và lưu vào tệp kết quả
while IFS= read -r line
do
  # Sử dụng tr để xóa dấu cách
  cleaned_line=$(echo "$line" | tr -d ' ')
  echo "$cleaned_line" >> "$output_file"
done < "$input_file"

echo "Đã xóa dấu cách và lưu vào $output_file."