Skip to content

Commit 3f56fe1

Browse files
authored
Create format.sh
1 parent 883959f commit 3f56fe1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

format.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# 检查是否提供了文件名作为参数
4+
if [ "$#" -ne 1 ]; then
5+
echo "Usage: $0 <file>"
6+
exit 1
7+
fi
8+
9+
input_file="$1"
10+
output_file="formatted_trackers.txt"
11+
12+
# 检查文件是否存在
13+
if [ ! -f "$input_file" ]; then
14+
echo "Error: File not found."
15+
exit 1
16+
fi
17+
18+
# 使用tr将逗号替换为换行符,然后使用grep和sed来处理文件
19+
# - 使用grep -oP 来匹配以http://, https://, udp://, wss://开头并且以/announce结尾的内容
20+
# - 不进行贪婪匹配
21+
# - 去除每行末尾的所有空格或制表符
22+
tr ',' '\n' < "$input_file" | \
23+
grep -oP '(http|https|udp|wss)://[^/]+/announce' | \
24+
sed 's/[ \t]*$//' > "$output_file"
25+
26+
echo "Formatted trackers have been saved to $output_file"

0 commit comments

Comments
 (0)