×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

@

1 sed "/^$/d" input.txt 2

#!/usr/bin/perl
( $wd, $mo, $md, $ti, $zone, $year) = split(/ +/, 'date', 6);
$now = time;
$yesterday = $now - (24*60*60);
$now = localtime;

$local_sec = (localtime($yesterday))[0];
$local_nim = (localtime($yesterday))[1];
$local_hr = (localtime($yesterday))[2];
$local_mdy = (localtime($yesterday))[3];
$local_mon = (Jan, Feb, Mar, Apr, May, Jun,
Jul, Aug, Sep, Oct, Nov, Dec)[((localtime($yesterday))[4])];
$local_yr = (localtime($yesterday))[5];
$local_wdy = (localtime($yesterday))[6];
$local_wdy = (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
[((localtime($yesterday))[6])];
#
printf "%s %s %2d %02d:%02d:%02d %s %d\n",
$local_wdy, $local_mon, $local_mdy,
$local_hr, $local_min, $local_sec,
$zone, 1900+$local_yr;
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / how to easily delete the empty lines in a text file under unix shell script and how to get the date of yesterday? Thanks
    • 1. sed -e "s/^$//" file.txt (iirc) 2. Depending on the OS. Different OSes have slightly different 'date' command.
      • that's stupid. it doesn't work. use grep -v
    • 1 sed "/^$/d" input.txt 2
      #!/usr/bin/perl
      ( $wd, $mo, $md, $ti, $zone, $year) = split(/ +/, 'date', 6);
      $now = time;
      $yesterday = $now - (24*60*60);
      $now = localtime;

      $local_sec = (localtime($yesterday))[0];
      $local_nim = (localtime($yesterday))[1];
      $local_hr = (localtime($yesterday))[2];
      $local_mdy = (localtime($yesterday))[3];
      $local_mon = (Jan, Feb, Mar, Apr, May, Jun,
      Jul, Aug, Sep, Oct, Nov, Dec)[((localtime($yesterday))[4])];
      $local_yr = (localtime($yesterday))[5];
      $local_wdy = (localtime($yesterday))[6];
      $local_wdy = (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
      [((localtime($yesterday))[6])];
      #
      printf "%s %s %2d %02d:%02d:%02d %s %d\n",
      $local_wdy, $local_mon, $local_mdy,
      $local_hr, $local_min, $local_sec,
      $zone, 1900+$local_yr;
    • 2.TZ=28; date
    • Thank you so much 2 guys. I will try it tomorrow