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