Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the leading spaces of the output from the command "uniq"?

Tags:

cat

cut

uniq

tr

[root@firstcentos scripts]# cat test1
00
00
01
01
00
00
02
02
03
aa
aa
aa
[root@firstcentos scripts]# cat test1 | uniq -c
      2 00
      2 01
      2 00
      2 02
      1 03
      3 aa
[root@firstcentos scripts]# 
like image 378
symb0l121cc00130 Avatar asked Oct 19 '25 11:10

symb0l121cc00130


1 Answers

If you want to remove the leading spaces, just pipe the output to sed to do so:

uniq -c file | sed 's/^\s*//'

Example:

$ uniq -c file
      2 00
      2 01
      2 00
      2 02
      1 03
      3 aa
$ uniq -c file | sed 's/^\s*//'
2 00
2 01
2 00
2 02
1 03
3 aa
like image 199
fedorqui 'SO stop harming' Avatar answered Oct 21 '25 11:10

fedorqui 'SO stop harming'