-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_links.sh
35 lines (27 loc) · 1.01 KB
/
mod_links.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
#!/bin/bash
# Define the input and output file
input_file="links.txt"
output_file="modified_links.txt"
# Replace "https://www.youtube.com/watch?v=" with "https://youtu.be/"
# Replace "&index=<VARIABLE STRING>" with "?"
# Remove the string "&list=<VARIABLE STRING>"
# Remove trailing "?" characters at the end of each line
# Replace "&pp=<VARIABLE STRING>" with "?"
# Replace "%3D" with ""
sed -e 's|https://www.youtube.com/watch?v=|https://youtu.be/|g' \
-e 's|%3D||g' \
-e 's|&index=[^&]*|?|g' \
-e 's|\&list=[^&]*||g' \
-e 's|\?$||' \
-e 's|&pp=[^&]*|?|g' "$input_file" > "$output_file"
# Remove trailing blank lines from the output file
sed -i '/^$/d' "$output_file"
# Sort the file alphabetically
sort -o "$output_file" "$output_file"
# Remove duplicate lines
uniq "$output_file" > "sorted_and_unique_links.txt"
# Rename the final file to the original name (optional)
mv "sorted_and_unique_links.txt" "$input_file"
# Remove the intermediate modified file
rm "$output_file"
echo "Modifications complete."