Linux sort combining -V and -f - linux

I want to combine sort -V and -f. Is there a way?
Here is simple example. I want to sort this list.
> cat testme
a1
a2
a11
a12
a3
A8
B8
b1
b11
Default sort is upper case first, lower case second, plus a11 comes before a2
> cat testme | sort
A8
B8
a1
a11
a12
a2
a3
b1
b11
I use -V which is awesome, a2 is before a11, but its still upper case then lower case
> cat testme | sort -V
A8
B8
a1
a2
a3
a11
a12
b1
b11
I can sort -f which fixes case, but a11 is still before a2
>cat testme | sort -f
a1
a11
a12
a2
a3
A8
b1
b11
B8
I try and combine them but -V wins and -f loses.
>cat testme | sort -f -V
A8
B8
a1
a2
a3
a11
a12
b1
b11
Is there an option to combine these?
Desired output is:
a1
a2
a3
A8
a11
a12
b1
B8
b11
Version in use:
[03:11:09] sa-hq1:~ # sort --version
sort (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

On my Fedora 25, it works properly.
[root#localhost ~]# sort --version
sort (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.
[root#localhost ~]# sort -Vf testme
a1
a2
a3
A8
a11
a12
b1
B8
b11
[root#localhost ~]#

You no need to cat file to sort command. It can read a file from stdin or from argument list:
sort -Vf file
or
sort -Vf < file
test:
~ > sort -Vf < file
a1
a2
a3
A8
a11
a12
b1
B8
b11
~ > sort -Vf file
a1
a2
a3
A8
a11
a12
b1
B8
b11
~ >

Related

sed : Insert line after n lines following the pattern

Pls bear with me as I knew this questions has been asked a few time by others, yet I keep getting error with the suggested answers.
Original file:
a1
a2
a3
product 2
b1
b2
b3
product 3
c1
c2
c3
I would like to add string '1111111' two lines after match pattern 'product', fetch to a file 'out'. Such like:
product 1
a1
a2
1111111
a3
product 2
b1
b2
1111111
b3
product 3
c1
c2
1111111
c3
Those links I referred are suggesting the command as below but I get an error:
sed '/product/{n;n;a \ 1111111'} file > out
sed: -e expression #1, char 0: unmatched `{'
I would like to achieve this using sed?
These are links I'm refering:
Insert line after match using sed
sed - insert line after X lines after match
Thank you.
Either adding the -e option as Hatless suggested, or add one linebreak after your a command:
$ sed '/product/{n;n;a\ 1111111
}' f
product 1
a1
a2
1111111
a3
product 2
b1
b2
1111111
b3
product 3
c1
c2
1111111
c3

Excel pivot/group/transpose

Data presented like this (3 rows with same key 1,2 etc):
k va vb
1 A11 B11
1 A12 B12
1 A13 B13
2 A21 B21
2 A22 B22
2 A23 B23
...
I need to group and transpose each group so I get (dont need keys even)
va1 vb1 va2 vb2 va3 vb3
A11 B11 A12 B12 A13 B13
A21 B21 A22 B22 A23 B23
...
You could use something like:
=INDEX($B$2:$C$7,(ROWS($A$1:$A1)-1)*3+(COLUMNS($A$1:A$1)-1)/2+1,2-MOD(COLUMNS($A$1:A$1),2))
Adjust the first range (the $B$2:$C$7 part) to match your actual data set

Excel formula to separate text between "\"

I have a path in
A1 C:\Users\fe\Desktop\01 Tur\2015\Kauk\Telu\Frame Report.pdf
A2 C:\Users\fe\Desktop\01 Tur\Deliveries\10 Toim\Alh\2005\Moot\CMC.doc
A3 C:\Users\fe\Desktop\01 Tur\Equip\Set\M-R\Kir\G3\sen.xls
etc.
I would like to separate these paths to (example for A1)
A2 "Users" | A3 "fe" | A4 "Desktop" | A5 "01 Tur" | A6 "2015" | A7 "Kauk" | A8 "Telu" | A9 "Frame Report.pdf"
I have tried to play with
=IF(ISERROR(FIND("\";A1;FIND("\";A1;1)+2));A1;LEFT(A1;FIND("\";A1;FIND("\";A1;1)+2)))
but it is not so suitable for multiplication. Is there any better solution that can be copied for this case?
With data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"\",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across:

finding Minimum value based on a range of values in another column in excel vba

10.00 b1
11.00 b2
22.00 b3
2.00 b1
323.00 b2
1.00 b3
423.00 b1
32.00 b2
42.00 b3
43.00 b1
522.00 b2
53.00 b3
22.00 b1
344.00 b2
33.00 b3
23445.00 b1
323.00 b2
4.00 b3
How can I find the minimum value of column1 where value of column2 = b2?
Here, I got one for you. It is an excel formula.
=MIN(IF(B1:B100="b2",A1:A100))

sort in bash, sort based part of column

I have a file like:
a1 blah
b2 blah
a3 blah
b1 blah
b3 blah
a2 blah
if I do
sort -k1,1 file.name
I'll get this:
a1
a2
a3
b1
b2
b3
However, I want to get this order:
a1
b1
a2
b2
a3
b3
how can I do that? Thanks
Edit: I edited the example, the previous one didn't present the whole problem
You are looking for sort -kN.M! N.M indicates sort to start from the Mth character on Nth field.
Initial solution:
sort -k1.2 your_file
Updated one:
sort -k1.2,k1.2 your_file
so it will just sort by this specific character and won't go further.
Output:
a1 blah
b1 blah
a2 blah
b2 blah
a3 blah
b3 blah

Resources