简体   繁体   English

如何使用Shell脚本读取文件内容

[英]How to read a file content using shell script

cat file.txt 
(
    while read line
    do
        initial_time=`head -n 1 $line| sed -e 's/\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]      [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1/'`
       initial_time_sec=`date -d "$initial_time" +%s`
    done
)

I want to take the date from every line , if it is less than 60 days I have to store it in variable 我想从每一行中获取日期,如果少于60天,则必须将其存储在变量中

while read line ; do
  initial_time=`echo $line | sed -e 's/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1/'`
  initial_time_sec=`date -d "$initial_time" +%s`
  now=`date +%s`
  pass_time=`expr $now - $initial_time_sec`
  limit_time=$((60 * 24 * 60))
  if [[ $pass_time -lt $limit_time ]]; then                                                                                                                                                                         
    echo $line
  fi  
done <data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM