I want to select a file name with a date that I generated in the past in the script.

Asked 1 years ago, Updated 1 years ago, 113 views

Currently, there is a file that was granted using the date command.
■ Example: 20180101.zip to 20180131.zip


From 9:00 on the selected date to 9:00 on the next day
without unzipping the zip, the line that corresponds to a particular string is
I wrote a script to find out how many lines there are, but it doesn't work.
Could you teach me?

  • When you want to display consecutive integers in the script, please let me know if there is a way to represent 01-31 instead of 1-31.
  • In order to select the two files to be referenced, I would like to see a configuration that can output a difference such as aa+1.

■ Command Example:

#!/bin/sh
i = 10
j = `$i+1`
while [$i-ne20];
do
echo"`ls201801"$i".zip201801"$j".zip | xargs-n1-IX unzip-p X | awk-F-"Dec"$i"09:00:00"<=$1&&$j"09:00"'|grep', allow,'|wc-l`"
  i = `expr$i+1`
  j = `expr$j+1`
done

Thank you for your cooperation.

linux shellscript

2022-09-30 21:30

2 Answers

When you want to display consecutive integers in the script, please let me know if there is a way to represent 01-31 instead of 1-31.

You can generate consecutive numbers with the seq command.I was able to format my version with -f.

$seq-f"%02.f"110
01
02
03
04
05
06
07
08
09
10

If the file name is the date, you can just pass it over.

$seq2018011020180120
20180110
20180111
20180112
20180113
20180114
20180115
20180116
20180117
20180118
20180120

In order to select the two files to be referenced, I would like to see a configuration that can output a difference such as aa+1.

You can use the expr command to calculate expressions expressed in strings.

$expr "1+1"
2

Combine for, seq, and expr

$for i in `seq2018011020180120`; do echo$i`expr$i+1`; done
20180110 20180111
20180111 20180112
20180112 20180113
20180113 20180114
20180114 20180115
20180115 20180116
20180116 20180117
20180117 20180118
20180118 20180119
20180119 20180120
20180120 20180121


2022-09-30 21:30

How many lines of content correspond to a particular string without unzipping the zip from 9:00 on the selected date to 9:00 on the next day

Instead of selecting a date, I thought about aggregating it by date (from the beginning to the end of the month).

unzip-p'201801*.zip'|
awk-F'[:]'
    $2>1&&$3<9&&$0~", allow, "{cnt[$2-1]++}
    $3>=9&&$0 ~", allow, "{cnt[$2+0]++}
  END{
    for(dincnt){
      printf("201801%02d:%d\n", d, cnt[d])
    }
  }
'

The unzip command argument is enclosed in a single quote ('201801*.zip') because it does not deploy wildcards (*) to the shell (expanded within unzip).
The awk script aggregates the number from midnight to 9:00 a.m. (cnt[$2-1]++) for the previous day ($2>1 to skip from midnight to 9:00 a.m. on January 1st (early Monday).(The code in the questionnaire says Dec.)…).


2022-09-30 21:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.