Baidu Script Pen Test two Way

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.