-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathextract.sh
More file actions
68 lines (49 loc) · 1.7 KB
/
Copy pathextract.sh
File metadata and controls
68 lines (49 loc) · 1.7 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Check if exactly one argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
# Get the filename from the argument
input_file=$1
# Check if the input_file matches the pattern raw.suss1 or raw.suss0
if ! [[ "$input_file" == "raw.suss1" || "$input_file" == "raw.suss0" ]]; then
echo "Filename does not match the pattern (raw.suss0 or raw.suss1)."
exit 1
fi
# Define the pattern to match
pattern="SUSSmsg cubic starts sending data. Follow id=[0-9]* for Sport=20480"
# Count the number of matching lines
matching_lines=$(grep -E "$pattern$" "$input_file" | wc -l)
if [ "$matching_lines" -ne 1 ]; then
echo "There are $matching_lines number of download in $input_file"
echo "This script only supports a single download test case."
exit 1
fi
suffix=${input_file##*.}
base_file="base.$suffix"
data_file="data.$suffix"
# Extract the id from the specific line
id=$(grep -Eo "SUSSmsg cubic starts sending data. Follow id=[0-9]+ for Sport=20480" "$input_file" | grep -Eo "id=[0-9]+" | cut -d '=' -f 2)
# Check if the id was found
if [ -z "$id" ]; then
echo "Pattern not found in the input file."
exit 1
fi
# Use grep to extract lines containing the id and save them to the output file
grep -E " id=$id " "$input_file" > "$base_file"
grep "@ id=" "$base_file" | sed 's/.*@ id=/id=/' |sed 's/=/ /g'> temp.temp
# Read the base time from the first line
base_time=$(awk 'NR==1 {print $4}' "temp.temp")
# Process the file and write to the output file
awk -v base_time="$base_time" '
{
if (NR == 1) {
$4 = 0
} else {
$4 = $4 - base_time
}
print
}' "temp.temp" > "$data_file"
rm temp.temp
echo "$data_file was created successfully."