묻다:문제의 주장을 위해 오늘이 26/03/15라고 가정합니다. 지난 5일 동안의 데이터를 어떻게 "누적"할 수 있습니까?
하지만 이 날짜는 단지 예시일 뿐입니다.. 이상적으로는 최종 데이터를 축적하고 싶습니다.엑스며칠, 누적되면 누적된 정보를 이메일로 보내드립니다. 나는 이 과정을 격일로 할 것이다지몇 주 동안 crontab을 통해 도움을 받으세요.
코드는 다음과 같습니다.
awk_variables=`echo "$line" | awk -F, '( $13 == "*OUT*" )||( $13 == "*IN*" ){print $1,$5,$10,$12,$13}' my_file.csv > /directory/some_directory/non_sorted_filtered.csv`
cat /directory/some_directory/non_sorted_filtered.csv | while read line
do
awk_variables="$line"
awk_variables_array=($awk_variables)
awk_time=${awk_variables_array[0]}
awk_container_ID=${awk_variables_array[1]}
awk_scan_count=${awk_variables_array[2]}
awk_part_number=${awk_variables_array[3]}
awk_direction==${awk_variables_array[4]}
awk_part_number_edited="${awk_part_number:3}"
awk_direction_edited="${awk_direction:1}"
awk_date=@''$awk_time
date=`date -d $awk_date +"%d/%m/%Y"`
echo -e "Date:$date Scan No:$awk_scan_count Part No:$awk_part_number_edited Direction:$awk_direction_edited"
done
출력은 다음과 같습니다.
Date:19/03/2015 Scan No:12 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:13 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:14 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:17 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:18 Part No:WTTO275 Direction:*OUT*
Date:19/03/2015 Scan No:19 Part No:WTTO275 Direction:*OUT*
Date:19/03/2015 Scan No:20 Part No:WTTO275 Direction:*OUT*
Date:20/03/2015 Scan No:22 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:23 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:24 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:25 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:26 Part No:XXXX1234567 Direction:*OUT*
Date:24/03/2015 Scan No:37 Part No:WTTO523 Direction:*OUT*
Date:25/03/2015 Scan No:43 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:44 Part No:SP-TMX6BP Direction:*OUT*
Date:25/03/2015 Scan No:45 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:49 Part No:02102 Direction:*OUT*
Date:25/03/2015 Scan No:50 Part No:02103 Direction:*OUT*
Date:25/03/2015 Scan No:51 Part No:02118 Direction:*OUT*
Date:25/03/2015 Scan No:52 Part No:02132 Direction:*OUT*
Date:25/03/2015 Scan No:53 Part No:02133 Direction:*OUT*
Date:25/03/2015 Scan No:54 Part No:02134 Direction:*OUT*
Date:25/03/2015 Scan No:55 Part No:02135 Direction:*OUT*
Date:25/03/2015 Scan No:56 Part No:19178 Direction:*OUT*
Date:25/03/2015 Scan No:57 Part No:19179 Direction:*OUT*
그래서 다음 데이터를 보내고 싶습니다.
Date:20/03/2015 Scan No:22 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:23 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:24 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:25 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:26 Part No:XXXX1234567 Direction:*OUT*
Date:24/03/2015 Scan No:37 Part No:WTTO523 Direction:*OUT*
Date:25/03/2015 Scan No:43 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:44 Part No:SP-TMX6BP Direction:*OUT*
Date:25/03/2015 Scan No:45 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:49 Part No:02102 Direction:*OUT*
Date:25/03/2015 Scan No:50 Part No:02103 Direction:*OUT*
Date:25/03/2015 Scan No:51 Part No:02118 Direction:*OUT*
Date:25/03/2015 Scan No:52 Part No:02132 Direction:*OUT*
Date:25/03/2015 Scan No:53 Part No:02133 Direction:*OUT*
Date:25/03/2015 Scan No:54 Part No:02134 Direction:*OUT*
Date:25/03/2015 Scan No:55 Part No:02135 Direction:*OUT*
Date:25/03/2015 Scan No:56 Part No:19178 Direction:*OUT*
Date:25/03/2015 Scan No:57 Part No:19179 Direction:*OUT*
알아채다:하루에 검사하는 횟수는 다양합니다. 때로는 100(예를 들어)일 수도 있고 때로는 0일 수도 있습니다.
답변1
이것은 해결책이라기보다는 팁에 가깝습니다. 내가 올바르게 기억한다면 ISO 8601
날짜 형식과 string compare
. 다음과 같은 것이 도움이 될 수 있습니다.
iso_moment=$(date -u +"%Y-%m-%dT%H:%M:%SZ" -d "-5 days")
iso_date=$(date -d $awk_date +"%Y-%m-%dT%H:%M:%SZ")
if [[ "${iso_date}" > "${iso_moment}" ]]
then
echo -e "Date:$date Scan No:$awk_scan_count Part No:$awk_part_number_edited Direction:$awk_direction_edited"
fi