1, write script implementation, you can use Shell, Perl and so on. Locate 100 files starting with ABC under directory/tmp, and then save the first line of these files to the file new.
2, write script implementation, you can use Shell, Perl and so on. Save all the rows in file B, but none in file a , to file C and count the number of lines in C.
Solution Ideas:
1: Feel better with the shell, the code is as follows
#!/bin/shfor filename in ' find/tmp-type f-name ' abc* ' |head-n ' dosed-n ' 1p ' $filename >>newdone |
Note: First, use the Find command, where-type F is the selection of ordinary files,-name used to set the file name, and the second, Head-n 100 command to remove the first 100 items. Third, sed-n ' 1p ' is used to remove the first line of the file. IV, >>new is appended to the file new.
2: The second topic or Perl is more convenient, the code is as follows:
[email protected] shellstudy]$ cat roc.pl
#!/usr/bin/perl-wopen B, "<b" or "die" B error. ($!) "; o Pen C, ">c" or Die "C error. ($!)"; My $find =0;my ($myb, $mya), while (<B>) {$find =0;chomp ($myb =$_);p rint "B", $myb, "\ n"; open A, "<a" or Die "a error." ( $!)"; while (<A>) {chomp ($mya =$_);p rint "A", $mya, "\ n", if ($mya =~/$myb/) {$find =1;print "find!\n";}} if ($find ==0) {print C $myb, "\ n";}} Close A;close b;close c; $linenum = ' Cat c|wc-l ';p rint "C line Count:", $linenum; |
Baidu Script Pen Test two Way