• linux 筛选当天生成的文件




    #!/bin/bash
    dt=`date "+%Y-%m-%d"`
    path=/home/vmuser/linbo/test_upload/data_file/unilever_sales_and_retrun/prod/
    echo $dt
    echo "ls --full-time $path | sed -n '/${dt}/p' | awk '{print $9}' "
    command="ls --full-time $path | sed -n '/${dt}/p' | awk '{print $9}' >/home/vmuser/linbo/kettleDemo/job/data/file.txt" 
    eval $command

    echo $?

    捎带介绍一下sed命令这两个选项:

    • -n选项:只显示匹配处理的行(否则会输出所有)(也就是关闭默认的输出)
    • -p选项:打印

    [vmuser@bd-c02 prod]$ vim test.txt
    [vmuser@bd-c02 prod]$ cat test.txt
    abcd;9527;efg
    hello shell
    [vmuser@bd-c02 prod]$ sed 's/9527/hello/' test.txt > target.txt 首先sed是有一个默认输出的,也就是将所有文件内容都输出,加上命令行中的替换,那么输出结果就是下面这样
    [vmuser@bd-c02 prod]$ cat target.txt
    abcd;hello;efg
    1035925174
    exit
    hello shell
    [vmuser@bd-c02 prod]$ sed 's/9527/hello/p' test.txt > target.txt 这行的意思就是:首先sed默认输出文件全部内容,然后p又将匹配到的内容打印了一遍,也就是会输出两边匹配到的内容
    [vmuser@bd-c02 prod]$ cat target.txt
    abcd;hello;efg
    abcd;hello;efg
    1035925174
    exit
    hello shell
    [vmuser@bd-c02 prod]$ sed -n 's/9527/hello/p' test.txt > target.txt 这行就是sed -n屏蔽默认输出然后s替换,p再将匹配到的内容打印出来,所以只显示了一行,也就是匹配到的那一行
    [vmuser@bd-c02 prod]$ cat target.txt
    abcd;hello;efg
    [vmuser@bd-c02 prod]$ sed -n 's/9527/hello/' test.txt > target.txt 这行就是sed -n选项屏蔽默认输出,s替换,但是没有p就不会将匹配到的内容输出
    [vmuser@bd-c02 prod]$ cat target.txt
    [vmuser@bd-c02 prod]$

  • 相关阅读:
    Matlab编辑器背景修改
    Booksim的运行
    illustrator画梯形
    latex去掉页眉
    latex字体颜色
    latex字体
    Methods to reduce the number of pipeline stages
    Basic Router Architecture
    Linux /sbin/service脚本一个基本无影响的bug
    HTML5实战之桌面通知
  • 原文地址:https://www.cnblogs.com/linbo3168/p/14174502.html
Copyright © 2020-2023  润新知