Find two files containing strings or strings that are not included in shell scripts

Source: Internet
Author: User

First, the demand

Here, I simplify, because this afternoon operation both texts are 10 tens of thousands of lines, but only filter out these two files contain the same or different string ppid.

Two, step together

1. Document HA1

Abc

2. Document HA2

Acd


3. Find out that two files contain a string ppid

3.1 Filtering scripts

#!/bin/sh#set-xsrc_file=$1target_file=$2result_file=$3> $RESULT _filewhile Read linedogrep $LINE $TARGET _file > /dev/nullif [$?-eq 0]; Thenecho $LINE >> $RESULT _filefidone < $SRC _file#set +x

3.2 Execution Results

[Email protected]]#./filter.sh ha1 ha2 ha3[[email protected]] #cat HA3AC


4. Find out if one of the files does not pack a string ppid

4.1 Modify $? Not equal to 0.

#!/bin/sh#set-xsrc_file=$1target_file=$2result_file=$3> $RESULT _filewhile Read linedogrep $LINE $TARGET _file > /dev/nullif [$?-ne 0]; Thenecho $LINE >> $RESULT _filefidone < $SRC _file#set +x

4.2 Execution Results

[Email protected]]#./filter.sh ha1 ha2 ha3[[email protected]] #cat ha3b


This article is from the "Scattered People" blog, please be sure to keep this source http://zouqingyun.blog.51cto.com/782246/1750069

Find two files containing strings or strings that are not included in shell scripts

Related Article

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.