I have to change the output of uniq -c: (example)
92 root
80 user
in
root 92
user 80
how can I do without using awk force?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityHere you go with GNU sed
:
... | sed -E 's/(\S*) (\S*)/\2 \1/'
Or POSIXly,
... | sed 's/\([^ ]*\) \(.*\)/\2 \1/'
uniq -c
output - the quantifier in the 1st group has to be +
(or \{1,\}
) to deal with the leading whitespace
Mar 23, 2018 at 15:22
uniq
implementation. The OP's seems to not output leading spaces. In any case, yes, using +
would help making it work with uniq
implementations that output leading spaces.
Mar 23, 2018 at 15:49
Here is a solution with cut and paste, given your input is a file and the delimiter is a space:
cut -d' ' -f1 input > temp1
cut -d' ' -f2 input > temp2
paste -d' ' temp2 temp1 > output
rm temp*
cut
other than copy/paste i'd be very very thankful.
uniq -c
output is exactly as posted by the OP (no leading spaces, columns separated by a single space) and if it's saved in a file you don't need temporary files etc you can simply run: paste -d' ' infile infile | cut -d' ' -f2,3
Mar 23, 2018 at 19:09