Awk specifies the row number and column number for processing

Source: Internet
Author: User

This method is problematic, and a specified line break should not be added to each line of the line break. I will study it later.

This problem occurs when processing a bunch of SQL files today.

The first problem is the separator. One of the two separators I encountered is "'" (reverse quotation marks) and "'" (single quotation marks ). Both of them are amazing. It is pointed out here first.

They are

Awk-F "'" 'In in {OFS = "'\''"}{....} 'filenameawk-F "\ '" 'In in {OFS = "'"}{...} 'filename'

Note that single quotation marks must be added to the left and right sides of the escape backslash of the target function.

Then there is the main problem. I want to make all the contents of the specified row and column of an SQL file in lowercase. Awk does not support the sed-I inplace mode and can only be replaced.

Note: The operation is risky. It is best to back up data first.

Awk-F "'" 'In in {OFS = "' \'' "} {If (NR> = 3 & Nr <= 20) {TMP = tolower ($2); $2 = TMP ;}; Print $0} 'filename> tmpfile

In this way, the changed content will be redirected to the specified file. Check the file and overwrite the original file.

 

Some may not understand why-F is already specified as a separator. Why do we need to specify OFS? This is because Print $0 is used later. If this parameter is not specified, the built-in separator awk, that is, space, is used for output by default, you will be surprised to find that the original "'" has become a space.

For other questions, you can easily find the answer by searching.

 

Awk specifies the row number and column number for processing

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.