From: Trag Date <101431599+tragdate@users.noreply.github.com> Date: Wed, 23 Aug 2023 01:43:04 +0000 (+0300) Subject: last: Add -T option for tab-separated output X-Git-Tag: v2.40-rc1~268^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d7df6b782cbd8c7852867a5dc9ff8cd69c23c0a;p=thirdparty%2Futil-linux.git last: Add -T option for tab-separated output This commit introduces a -T option to the last command, allowing for tab-separated output. This change significantly improves the usability of last in conjunction with awk, enabling more efficient and intuitive parsing of command output. Signed-off-by: Cristian Zmole --- diff --git a/login-utils/last.c b/login-utils/last.c index eaebc1fe6a..dced3f86f0 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -95,6 +95,7 @@ struct last_control { time_t until; /* at what time to stop displaying the file */ time_t present; /* who where present at time_t */ unsigned int time_fmt; /* time format */ + char separator; /* output separator */ }; /* Double linked list of struct utmp's */ @@ -520,24 +521,24 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t if (ctl->showhost) { if (!ctl->altlist) { len = snprintf(final, sizeof(final), - "%-8.*s %-12.12s %-16.*s %-*.*s %-*.*s %s\n", - ctl->name_len, p->ut_user, utline, - ctl->domain_len, domain, - fmt->in_len, fmt->in_len, logintime, fmt->out_len, fmt->out_len, - logouttime, length); + "%-8.*s%c%-12.12s%c%-16.*s%c%-*.*s%c%-*.*s%c%s\n", + ctl->name_len, p->ut_user, ctl->separator, utline, ctl->separator, + ctl->domain_len, domain, ctl->separator, + fmt->in_len, fmt->in_len, logintime, ctl->separator, fmt->out_len, fmt->out_len, + logouttime, ctl->separator, length); } else { len = snprintf(final, sizeof(final), - "%-8.*s %-12.12s %-*.*s %-*.*s %-12.12s %s\n", - ctl->name_len, p->ut_user, utline, - fmt->in_len, fmt->in_len, logintime, fmt->out_len, fmt->out_len, - logouttime, length, domain); + "%-8.*s%c%-12.12s%c%-*.*s%c%-*.*s%c%-12.12s%c%s\n", + ctl->name_len, p->ut_user, ctl->separator, utline, ctl->separator, + fmt->in_len, fmt->in_len, logintime, ctl->separator, fmt->out_len, fmt->out_len, + logouttime, ctl->separator, length, ctl->separator, domain); } } else len = snprintf(final, sizeof(final), - "%-8.*s %-12.12s %-*.*s %-*.*s %s\n", - ctl->name_len, p->ut_user, utline, - fmt->in_len, fmt->in_len, logintime, fmt->out_len, fmt->out_len, - logouttime, length); + "%-8.*s%c%-12.12s%c%-*.*s%c%-*.*s%c%s\n", + ctl->name_len, p->ut_user, ctl->separator, utline, ctl->separator, + fmt->in_len, fmt->in_len, logintime, ctl->separator, fmt->out_len, fmt->out_len, + logouttime, ctl->separator, length); #if defined(__GLIBC__) # if (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0) @@ -584,6 +585,7 @@ static void __attribute__((__noreturn__)) usage(const struct last_control *ctl) fputs(_(" -R, --nohostname don't display the hostname field\n"), out); fputs(_(" -s, --since