Reverse specific field number

Hello everybody :slight_smile:
I have specific problem when i use

rev | uniq -f 3 -c | rev

ORIGINAL Output-
(without rev | uniq -f 3 -c | rev)

tibenska13 Oct 30 00:26

firsth

rev

OUTPUT-

62:00 03 tcO 31aksnebit

after

uniq -f 3 -c

OUTPUT-

19 62:00 03 tcO 31aksnebit

after next

rev

OUTPUT-

tibenska13 Oct 30 00:26 91

String is revert well bud number is wrong.
Number is 91 but badly reverted...
Must be 19 not 91
I need to revert this field again,
How can i do it ?

Please tell us more about your input file and describe, in English, what you are trying to produce as output.

I don't see how you get uniq -f 3 -c to give you a count of 19 matching lines when you only have one line of input in your sample file?

How is your sample input file ordered (assuming there is more than one line in your input file?

If you only have one value in the 1st field in your input file, why not just print the 1st line of the file and use wc -l to add the line count?

last | tr -s ' ' | cut -d\  -f1,5-7 | sort -s -t ' ' -k1,1 | rev | uniq -f | rev

This is the code i need reverse specific field is that possible ?
using maybe awk . . .

I don't understand. What exactly do you want to achieve? What's the rev for?

---------- Post updated at 11:45 ---------- Previous update was at 11:33 ----------

IF your intention is to print a login count per user, and IF your uniq offers the -w option, this might help you:

last | sort -t ' ' -k1,1 | uniq -w6 -c | tr -s ' ' '   ' | cut -d'     ' -f2,3,6-8
usage: uniq [-c | -du | -i] [-f fields] [-s chars] [input [output]]

I am using FreeBSD 3.2-RELEASE so optin -w doesn't work.

INPUT -

koren14          ttyp9    tomo100.ynet.sk  Thu Oct  1 10:34 - 11:37  (01:03)
kanuch14         ttyp8    pe3k.ynet.sk     Thu Oct  1 10:27 - 10:39  (00:11)
baranek13        ttyp7    188-167-149-232. Thu Oct  1 09:54 - 14:05  (04:11)
lastinec         ttyp3    147.175.145.131  Thu Oct  1 09:52 - 12:09  (02:16)
baranek13        ttyp7    188-167-149-232. Thu Oct  1 09:32 - 09:54  (00:21)
labaj13          ttyp7    147.175.123.164  Thu Oct  1 09:22 - 09:24  (00:02)
knapik13         ttyp9    cpu-c04.ucebne.f Thu Oct  1 09:12 - 09:41  (00:29)
jelencik13       ttyp8    cpu-c05.ucebne.f Thu Oct  1 09:12 - 09:19  (00:07)
pavkovce14       ttyp7    pavkovcek.ynet.s Thu Oct  1 09:10 - 09:13  (00:03)
nemec14          ttyp3    151.236.226.58   Thu Oct  1 09:05 - 09:32  (00:27)
vozar14          ttyp3    fvozar.eu        Thu Oct  1 09:01 - 09:01  (00:00)
slovikm13        ttyp3    217.119.114.218  Thu Oct  1 08:49 - 08:50  (00:00)
nemec14          ttyp7    151.236.226.58   Thu Oct  1 08:33 - 08:40  (00:06)
lam13            ttyp4    fei-free-27.wifi Thu Oct  1 08:33 - 10:53  (02:19)
lastinec         ttyp3    chello0891730632 Thu Oct  1 08:23 - 08:47  (00:23)

wtmp begins Thu Oct  1 08:23:46 2015

You still didn't say what you want to achieve - so, good luck with whatever this might be.

@RudiC
go to start and read again post...

Try:

last | sort | awk '
NF < 7 {next
}
last != $1 {
	if(NR > 1)	print c
	if($5 ~ /^[0-9]+$/)
		printf("%s %s %s %s ", $1, $4, $5, $6)
	else	printf("%s %s %s %s ", $1, $5, $6, $7)
	last = $1
	c = 0
}
{	c++
}
END {	print c
}'

The second if statement in the awk script allows you to capture the data you want from local logins (and from the wtmp line) as well as from remote logins.

If you replace last in that pipeline with cat filename where filename is the name of a file that contains the data you provided in post #5, you'll get the output:

baranek13 Oct 1 09:32 2
jelencik13 Oct 1 09:12 1
kanuch14 Oct 1 10:27 1
knapik13 Oct 1 09:12 1
koren14 Oct 1 10:34 1
labaj13 Oct 1 09:22 1
lam13 Oct 1 08:33 1
lastinec Oct 1 09:52 2
nemec14 Oct 1 09:05 2
pavkovce14 Oct 1 09:10 1
slovikm13 Oct 1 08:49 1
vozar14 Oct 1 09:01 1
wtmp Oct 1 08:23:46 1

If you don't want the wtmp line to be included in your output, change the following line in the awk script:

NF < 7 {next

to:

NF < 8 {next