(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.
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)
{
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);
}
}
++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;