Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use shell script to skillfully count files

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use shell script clever statistical files, many people may not understand, in order to make you better understand, the editor summed up the following content, I hope you can get something according to this article.

In the process of data migration, a large number of dump files will be generated, which requires a simple and clear management of dump files. For example, there are a large number of files in the directory, and some tables are relatively large, corresponding to more dump files, so you want to get a very concise report that can count how many dump files there are in each table.

For example, there are 1000 dump files, all based on the table TEST1,TEST2,TEST3,TEST4. Then you want to get a simple statistical report, similar to the following form

TEST1 100 TEST2 450 TEST3 300 TEST4 150

Briefly simulate this problem.

Use the following script a.sh to generate the DUMP file.

For i in {1... 2} do touch $1_EXT_$i.dmp done

Generate these 1000 dump files.

[ora11g@rac1 DUMP] $ksh a.sh TEST1 100 [ora11g@rac1 DUMP] $ksh a.sh TEST2 450 [ora11g@rac1 DUMP] $ksh a.sh TEST3 300 [ora11g@rac1 DUMP] $ksh a.sh TEST4 150 [ora11g@rac1 DUMP] $ll * .dmp | wc-l 1000

Take a brief look at the generated dump.

[ora11g@rac1 DUMP] $ll * .dmp | tail-10-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_91.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_92.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_93.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_94.dmp-rw -Rafael ora11g dba-1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_95.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_96.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_97.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_98.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_99.dmp-rw-r--r-- 1 ora11g dba 0 Aug 7 08:13 TEST4_EXT_9.dmp [ora11g@rac1 DUMP] $

The first thing you need to get is that there are several related tables in this directory.

For example, in the current situation, you need to get the

TEST1 TEST2 TEST3 TEST4

You can use the following command to get the statistics.

[ora11g@rac1 DUMP] $ls-lrt * .dmp | awk'{print $9}'| awk-F_EXT'{print $1}'| uniq TEST1 TEST2 TEST3 TEST4

Then go a step further, how to get how many dump files each table corresponds to.

You can use the following script b.sh to quickly get

Ls-lrt * .dmp | awk'{print $9}'| awk-F_EXT'{print $1}'| uniq | xargs-I echo "echo {}\ `ls-lrt {} _ EXT_ [0-9] * .dmp | wc-l\ `> tablst" > test.sh ksh test.sh rm test.sh [ora11g@rac1 DUMP] $ksh b.sh [ora11g@rac1 DUMP] $cat tablst TEST1 100TEST2 450 TEST3 300 TEST4 150

In this way, the statistical work of the documents will be very clear.

After reading the above, do you have any further understanding of how to use clever statistical files in shell scripts? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report