-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpadomatic
More file actions
executable file
·49 lines (37 loc) · 1.17 KB
/
padomatic
File metadata and controls
executable file
·49 lines (37 loc) · 1.17 KB
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
48
49
#!/usr/bin/bash
Tmp=/tmp/$$
Tmp1=/tmp/$$_$$
trap 'exit 0' INT HUP QUIT TERM ALRM USR1
trap 'rm -f "$Tmp" "$Tmp1"' EXIT
rm -f "$Tmp" >/dev/null 2>&1
rm -f "$Tmp1" >/dev/null 2>&1
#================================================================
# paste -d' ' file1 file2 > output_file
source ~/bash.library
# Get the filename from the command-line argument
filename="$1"
# Check if a filename is provided
if [ -z "$filename" ]; then
echo "Usage: $0 <filename>"
exit 1
fi
# Check if the file exists
if [ ! -f "$filename" ]; then
echo "Error: File '$filename' not found."
exit 1
fi
backup_file "$filename" ~/BACKUPS
sed 's/[[:space:]]*$//' "$filename" > $Tmp
# Find the longest line length
max_len=$(wc -L "$Tmp" | awk '{print $1}')
# Calculate the padding length
padding_length=$((max_len + 1))
# Create a temporary file to store the padded content
temp_file=$(mktemp)
# Iterate through each line of the file and pad it
while IFS= read -r line; do
printf "%-${padding_length}s\n" "$line" >> "$temp_file" # Pad to the right
done < "$Tmp"
# Replace the original file with the padded content
cat "$temp_file" > "$filename"
# echo "File '$filename' padded successfully."