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

Other diffs: Previous Major Revision, Previous Author

Newer page: version 5 Last edited on Sunday, 3 October 2010 3:43:56 by CyberLeo Revert
Older page: version 4 Last edited on Sunday, 3 October 2010 3:43:11 by CyberLeo Revert
@@ -14,8 +14,9 @@
 </code> 
  
 <code brush="bash"> 
 expand "${file}" | sed -ne ' 
+s/#.*$//g # Strip out all comments, as they may interfere  
 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 

version 5

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/#.*$//g     # Strip out all comments, as they may interfere
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
}'