]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(cut_bytes): Print at least a newline for every line of input.
authorJim Meyering <jim@meyering.net>
Wed, 2 Nov 1994 05:04:17 +0000 (05:04 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 2 Nov 1994 05:04:17 +0000 (05:04 +0000)
(cut_fields): Print a newline even for lines whose only selected
field is empty.  But print nothing when using -s without -f1.
And print nothing for empty input.  Reported by
Richard_Sharman@software.mitel.com.

src/cut.c

index 0087880e49e51328b83d892c17f26975073a5913..755de7390c705f51ed439dc095821c324214f9a0 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -495,9 +495,7 @@ cut_bytes (stream)
      FILE *stream;
 {
   int byte_idx;                        /* Number of chars in the line so far. */
-  int printed_from_curr_line;
 
-  printed_from_curr_line = 0;
   byte_idx = 0;
   while (1)
     {
@@ -505,21 +503,22 @@ cut_bytes (stream)
 
       c = getc (stream);
 
-      if (c == '\n' || c == EOF)
+      if (c == '\n')
        {
-         if (printed_from_curr_line)
-           putchar ('\n');
-         if (c == EOF)
-           break;
-         printed_from_curr_line = 0;
+         putchar ('\n');
          byte_idx = 0;
        }
+      else if (c == EOF)
+       {
+         if (byte_idx > 0)
+           putchar ('\n');
+         break;
+       }
       else
        {
          ++byte_idx;
          if (print_kth (byte_idx))
            {
-             printed_from_curr_line = 1;
              putchar (c);
            }
        }
@@ -620,7 +619,8 @@ cut_fields (stream)
        ++field_idx;
       else if (c == '\n' || c == EOF)
        {
-         if (found_any_selected_field)
+         if (found_any_selected_field
+             || !(suppress_non_delimited && field_idx == 1))
            putchar ('\n');
          if (c == EOF)
            break;