Note: You are viewing an old version of this page. View the current version.

Differences between version 4 and previous revision of KnowledgeBase/Scripts/longlines.sh.

Other diffs: Previous Major Revision, Previous Author

Newer page: version 4 Last edited on Sunday, 3 October 2010 3:43:11 by CyberLeo Revert
Older page: version 3 Last edited on Sunday, 3 October 2010 3:03:09 by CyberLeo Revert
@@ -14,18 +14,19 @@
 </code> 
  
 <code brush="bash"> 
 expand "${file}" | sed -ne ' 
-/[^\\]$/ {  
- H  
- s/.*//g  
- x  
- s/^\n//g  
- s/\n/ /g  
- s/ */ /g  
-
+s/ *$// # Remove end-of-line whitespace  
+ /[^\\]$/ { # If the line doesn't end with a backslash, print the whole thing  
+ H # Append current line to hold  
+ s/.*//g # Clear pattern so that hold will be emptied  
+ x # Exchange (hold is empty, pattern has what we want)  
+ s/^\n//g # Remove initial newline, caused by appending to empty buffer  
+ s/\n/ /g # Change newlines to spaces  
+ s/ */ /g # Squash extra spaces  
+ p # Print  
 
-/\\$/ {  
- s/\\$//  
-
+/\\$/ { # If the line ends with a backslash, append it to hold without backslash  
+ s/\\$// # Remove tailing backslash  
+ H # Append to hold  
 }' 
 </code> 

version 4

This will translate a file that consists of backslash-newline broken lines into a file with single long lines, and squash whitespace.

For example:

acpi_quirks.h                   optional acpi                              \
        dependency      "$S/tools/acpi_quirks2h.awk $S/dev/acpica/acpi_quirks" \
        compile-with    "${AWK} -f $S/tools/acpi_quirks2h.awk $S/dev/acpica/acpi_quirks" \
        no-obj no-implicit-rule before-depend                              \
        clean           "acpi_quirks.h"

becomes

acpi_quirks.h optional acpi dependency "$S/tools/acpi_quirks2h.awk $S/dev/acpica/acpi_quirks" compile-with "${AWK} -f $S/tools/acpi_quirks2h.awk $S/dev/acpica/acpi_quirks" no-obj no-implicit-rule before-depend clean "acpi_quirks.h"
expand "${file}" | sed -ne '
s/ *$//       # Remove end-of-line whitespace
/[^\\]$/ {    # If the line doesn't end with a backslash, print the whole thing
  H           # Append current line to hold
  s/.*//g     # Clear pattern so that hold will be emptied
  x           # Exchange (hold is empty, pattern has what we want)
  s/^\n//g    # Remove initial newline, caused by appending to empty buffer
  s/\n/ /g    # Change newlines to spaces
  s/  */ /g   # Squash extra spaces
  p           # Print
}
/\\$/ {       # If the line ends with a backslash, append it to hold without backslash
  s/\\$//     # Remove tailing backslash
  H           # Append to hold
}'