Julie Kurpa
asked on
Powershell: Remove Blank line that follows a line which contains a specific string
I'd like to search a large text file in Windows and remove the blank line after a line that contains a specific string.
Here's a snippet of the file content which contains the string:
COMPILE SPECIFICATION
PLSQL_OPTIMIZE_LEVEL= 2
PLSQL_CODE_TYPE= INTERPRETED
PLSQL_DEBUG= FALSE PLSCOPE_SETTINGS= 'IDENTIFIERS:NONE' <-- this is the string
<-- this is the blank line.
/
I want the string to be without the blank line before the "/" like below:
COMPILE SPECIFICATION
PLSQL_OPTIMIZE_LEVEL= 2
PLSQL_CODE_TYPE= INTERPRETED
PLSQL_DEBUG= FALSE PLSCOPE_SETTINGS= 'IDENTIFIERS:NONE'
/
I opened the file in Notepad++ and can see the CRLF at the end of the lines. Can't figure out how to get Notepad++ to do this for me.
It seems Powershell should be able to do it.
But I can only find examples (that I can understand) which remove all carriage returns rather than the carriage return after a specific string.
Or it removes all blank lines, but I don't want to do this for ALL blank lines. I only want to remove the blank line after that particular string.
Much appreciation for your help.
Here's a snippet of the file content which contains the string:
COMPILE SPECIFICATION
PLSQL_OPTIMIZE_LEVEL= 2
PLSQL_CODE_TYPE= INTERPRETED
PLSQL_DEBUG= FALSE PLSCOPE_SETTINGS= 'IDENTIFIERS:NONE' <-- this is the string
<-- this is the blank line.
/
I want the string to be without the blank line before the "/" like below:
COMPILE SPECIFICATION
PLSQL_OPTIMIZE_LEVEL= 2
PLSQL_CODE_TYPE= INTERPRETED
PLSQL_DEBUG= FALSE PLSCOPE_SETTINGS= 'IDENTIFIERS:NONE'
/
I opened the file in Notepad++ and can see the CRLF at the end of the lines. Can't figure out how to get Notepad++ to do this for me.
It seems Powershell should be able to do it.
But I can only find examples (that I can understand) which remove all carriage returns rather than the carriage return after a specific string.
Or it removes all blank lines, but I don't want to do this for ALL blank lines. I only want to remove the blank line after that particular string.
Much appreciation for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FWIW... to answer how to do it it Notepad++
Find what: ^( PLSQL_DEBUG= FALSE.+)\r\n$
Replace with: \1
Find what: ^( PLSQL_DEBUG= FALSE.+)\r\n$
Replace with: \1
ASKER
It worked!!! Thank you!