-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamassbeautifier.sh
47 lines (38 loc) · 979 Bytes
/
amassbeautifier.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
remove_ansi_codes() {
local input_text="$1"
echo "$input_text" | awk '{gsub(/\x1b\[[0-9;]*[a-zA-Z]/, "")}1'
}
main() {
input_file=""
output_file=""
while [[ $# -gt 0 ]]; do
case $1 in
-i | --input)
input_file=$2
shift 2
;;
-o | --output)
output_file=$2
shift 2
;;
*)
echo "Invalid option: $1"
exit 1
;;
esac
done
if [[ -z $input_file || -z $output_file ]]; then
echo "Usage: $0 -i <input_file> -o <output_file>"
exit 1
fi
if [[ ! -f $input_file ]]; then
echo "Error: Input file '$input_file' not found!"
exit 1
fi
text=$(cat "$input_file")
clean_txt=$(remove_ansi_codes "$text")
echo "$clean_txt" > "$output_file"
echo "Success! Clean text saved to $output_file"
}
main "$@"