Use AWK for data file Detection

Source: Internet
Author: User

When AWK is used for data file detection, it is necessary to detect the data file. Check whether it meets the requirements. For example, the fields in the generated data file are separated by 0x06. Records are separated by line breaks (one record occupies one row ). A row contains 29 fields. Therefore, I only need to determine whether the field column is 29 after 0x06 is used in each row. If it is less than 29, the data is certainly faulty. Output the row number and column number of fields. After Online exploration, use the following statement: awk-F' [\ 06] ''{I = 1; while (I <NF) {I ++} if (I <29) {print FNR, NF;} '201301_152118_all1_info.txt use the preceding statement to detect the 201301_152118_all1_info.txt data file. If the data is incorrect, the row number and field column number are printed, and the bug is determined. Locate the bug. The bug can be solved. It's easy. Just filter out the carriage return and line feed. Use the following code to filter out null values: // block the null value and return the null String private String getString (String strInfo) {String result = ""; if (null! = StrInfo &&! "". Equals (strInfo) {Pattern p = Pattern. compile ("\ t | \ r | \ n"); Matcher m = p. matcher (strInfo); result = m. replaceAll (""); // filter the tab, press enter, and line feed} return result ;}

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.