linux python 新建脚本文件夹,遍历Linux文件夹下文件的Shell(及python)脚本

1、脚本查看

nisjdeMacBook-Pro:Downloads nisj$ cat traveDir.sh

#!/usr/bin/env bash

function read_dir(){

for file in `ls $1`

do

if [ -d $1"/"$file ]

then

read_dir $1"/"$file

else

cat $1"/"$file|grep "command=sh /data/etl/sh/agr_common.sh dim"|awk -F" " '{print $3}'>>/Users/nisj/Downloads/runigJob.sql

fi

done

}

rm -rf /Users/nisj/Downloads/runigJob.sql

read_dir $1

2、调用示例

sh traveDir.sh /Users/nisj/WptWork/gitOnline/azkaban-job/src/etl-scheduler-subflow

3、注意说明

3.1、调用格式是:[sh traveDir.sh 要遍历的路径]

3.2、[awk -F" " '{print $3}']的使用

3.3、Shell函数的使用

3.4、结果文件查看

nisjdeMacBook-Pro:Downloads nisj$ cat runigJob.sql

dim_regist_sc_1d

dim_sale_id_snap_1d

dim_sale_uri_snap_1d

dim_sc_webtype_1d

dim_seller_base_snap_1d

dim_seller_cfc_organization_full_1d

dim_share_documents_full_chain_1d

dim_template_category_chain_1d

dim_user_base_curr_snap_1d

dim_userinfo_snap_full_1d

dim_user_yj_artisan_full_1d

dim_userinfo_address_full_1d

dim_userinfo_basic_info_full_1d

dim_product_category_full_1d

nisjdeMacBook-Pro:Downloads nisj$

3.5、一个查找文件中包含固定字符串的python脚本

/Users/nisj/Documents/wptDataGit-nisj/wptData/pyScript/love/findFile.py

# encoding: utf-8

import os

def find(find_text):

os.system("""find /Users/nisj/WptWork/gitOnline/etl/sql -maxdepth 1 -type f -name '*.sql'|xargs grep -n '{find_text}'|grep -v '\--'>>/Users/nisj/Downloads/ods_dependent.sql""".format(find_text=find_text));

find_text_list=['ods_activity_sale_apply_full_1d',

'ods_activity_sale_apply_full_1d_old',

'ods_alcohol_alcohol_exchange_full_1d',

'ods_alcohol_alcohol_full_1d',

'ods_alcohol_alcohol_order_full_1d',

'ods_alcohol_alcohol_pay_full_1d',

'ods_alcohol_currency_exchange_full_1d']

os.system(

"rm -rf /Users/nisj/Downloads/ods_dependent.sql");

for find_text in find_text_list:

find(find_text=find_text)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值