13
votes
Accepted
Why does `htop` display `$'\t'` as `?` in `sort` command?
There’s nothing wrong with your command, htop replaces control characters with question marks:
(((unsigned char)data_c[j]) >= 32 ? ((unsigned char)data_c[j]) : '?')
(characters with values less ...
12
votes
Accepted
sort the whole .csv based on the value in a certain column
So, you want to sort (stably) on revenue in numerically descending order, which sounds like it should be easy in Miller except that its rules for null handling say:
Records with one or more empty ...
12
votes
sort the whole .csv based on the value in a certain column
Using sort:
cat input.csv | (sed -u 1q; sort -t, -r -n -k5)
The sed -u 1q is required to make the sort ignore the header. It basically means, process the 1st line and quit, then pass the remaining ...
8
votes
sort the whole .csv based on the value in a certain column
Using mandatory POSIX tools available on all Unix systems:
$ { head -n 1; sort -t, -k5,5rn; } < file
name,location,capital,profit-lost,revenue,employees,year
company8,location8,6161574.62,906591.96,...
7
votes
Accepted
Collect chars from strings and print their unicode
With perl:
perl -C -lne '
if (/=(.*)/) {$c{$_}++ for split //, $1}
END{print join ",", map {sprintf "0x%X", ord$_} sort keys %c}
' your-file
Gives:
0x42,0x46,0x61,0x63,0x64,...
6
votes
Sort by 3 different columns with numbers and text aix
Assuming the text between the timestamp and the duration always has 3 blank-separated words like in your sample, you could do:
<your-file LC_ALL=C sort -nb -k6.2,6 -k8,8 -k10,10
The default ...
6
votes
Accepted
Why is ls sorting Chinese filenames by length?
You'll notice that among the strings of same length, there appears to be a relative order of those characters, so they're not totally treated as being equivalent. It's not like the 🧚🧛🧜 which have ...
4
votes
Sort by 3 different columns with numbers and text aix
A Perl approach:
$ perl -lne '/(\d+)\s*hrs\s*(\d+)\s*mins\s*([0-9.]+)\s*Secs/;
push @{$k{($1*60*60)+($2*60)+($3)}},$_;
}{
for $t (sort {$a <=> $b} keys(%...
4
votes
Accepted
Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"
CSV is a structured document format. As such, simple text manipulation tools like cut (or sort, sed, or awk, unless the data is simple) are inadequate for processing CSV files safely and conveniently ...
4
votes
MAC OSX / Bash Problem - Sorting strings as a date
On OSX, you should have access to zsh which will allow you to make use of its glob qualifiers to sort matching filenames by modification time
/Volumes/myVolume/**/*(.DOm)
You can then utilize its ...
4
votes
ls starting at particular file
If you use zsh as your shell, then you could use its glob qualifiers to select only those filenames that do not sort lexicographically before the chosen file1.
Ex. given
% ls -1
alpha.mp3
bar.xls
...
3
votes
Sort a list of filenames such that files in subdirectories are listed before files in the parent directory
Here a simple way:
awk 'BEGIN{FS="/"; OFS="\t"}{print NF, $0}' file | sort -rn | cut -f2-
A1/B1/file
A2/file
A1/file
file
Should works for simple cases, like your question.
If ...
3
votes
Sort file array list in bash by date and bypass argument limit
With newer versions of GNU ls and bash, you can do:
readarray -td '' new_array < <(
ls --zero -dt -- "${array_list[@]}")
That doesn't bypass the execve() limit on the length of ...
3
votes
how to list all files in a given period according their duration(not moment) of access
That information is not available by default, but you could log from now on and then process the result to get what you need.
In theory there are many ways to log it, depending on the processes that ...
3
votes
sort the whole .csv based on the value in a certain column
The duckdb db cli is really a great tool, and it's simply SQL
duckdb -csv -c "select * from read_csv_auto('input.csv') order by revenue desc"
And you get
name,location,capital,profit-lost,...
3
votes
MAC OSX / Bash Problem - Sorting strings as a date
ls itself has the capability to sort files based on date:
ls -l[r]t
Hence, you could work "backwards": instead of using ls first and sort afterwards prepare the list of files first and ...
3
votes
Accepted
Pipe null terminated file paths twice to same output, but second time sorted by basename
With perl, that could look like:
find . ... -print0 |
perl -MFile::Basename -0 -lne '
print; push @files, $_;
END {
print $_->[0] for sort {$a->[1] cmp $b->[1]} map {[$_, ...
3
votes
Does a command exist that lists all the directories where a word appears in a file or directory name?
Well, if on a GNU system, you could use GNU find's -printf which allows you to specify the output format. Sticking to sort is fine, as having separate commands for specific tasks somehow fulfils the ...
3
votes
How to sort the list of positional parameters in POSIX sh
Probably easiest is to resort to awk which can do strcoll(), strcmp(), and number comparisons (including of floating points).
To avoid reinventing the wheel, we can use the quicksort awk ...
2
votes
Accepted
Pipe containing sort and awk writes too many files to disk while taking random lines from files and ultimately fails due to unavailable storage
I don't really understand why you're taking this approach and I suspect it wouldn't work anyway since rand() isn't getting reinitialized and is likely always giving the exact same output. Try it:
$ ...
2
votes
Accepted
Sort a list of filenames such that files in subdirectories are listed before files in the parent directory
zsh has the od glob qualifier to order glob expansions depth-first,
$ print -rC1 -- **/file(Nod)
A2/file
A1/B1/file
A1/file
file
That can be applied to an arbitrary list of files, if that list of ...
2
votes
Collect chars from strings and print their unicode
Should be doable with an iconv | hexdump.
Terse proof-of-concept for your sample input:
cut -d= -f2- | iconv -t UTF-32LE | hexdump -ve '"0x%02X,"'
NOTE: the above command works as expected ...
2
votes
sort the whole .csv based on the value in a certain column
Using Raku (formerly known as Perl_6)
~$ raku -e 'lines.head.put; my @a = lines(); .put for @a.sort(-*.split(",")[4]);' file
#OR
~$ raku -e 'lines.head.put; .put for lines.sort(-*.split(&...
2
votes
How to sort and filter images by modification time and view them in nsxiv on FreeBSD
You'll have to properly go through xargs to get the sorting done; so, something like
find . -maxdepth 1 -type f \
\( -iregex '.+\.jpe?g$' -o -iregex '.+\.png$' \) \
-newermt 2023-10-01 \
-...
2
votes
How to sort and filter images by modification time and view them in nsxiv on FreeBSD
If it is important for you to be able to make it work on a vanilla FreeBSD system there is another answer with find/xargs/cut/stat. If you are able to install additional utilities there is a cleaner ...
2
votes
Sorting a text file based on numerical values present in each line
If your file names are exactly as you show, you want to sort numericaly on the 5th field defined by _:
/home/wav_path/converted_Interpreter_TC_1.wav
_________ ______________ ___________ __ _____
1st ...
2
votes
How exactly does Nautilus sort files by name?
By default, 'ls' uses the libc locale-specific sort order, the same as used by 'sort'. For all *.UTF-8 locales (except C.UTF-8), Glibc implements the Unicode Collation Algorithm (or something close to ...
2
votes
How to sort the list of positional parameters in POSIX sh
you need to use the shell to eval these string first, and then can sort the results, applying the same operations to the strings that get sorted, and the array of original indices. I'll illustrate ...
1
vote
sort the whole .csv based on the value in a certain column
MacOS has Ruby as a default and Ruby has a csv parser built in.
Here is a ruby:
ruby -r csv -e 'tbl=CSV.parse($<.read, **{:headers=>true, :converters=>:all}).to_a
header=tbl.shift
...
1
vote
What is the difference between sort < and sort without '<'?
The differences are:
With
sort < filename
the parent shell opens filename, and connects it to sort's STDIN I/O stream. sort runs, sees no command line filenames, and simply reads STDIN and sorts.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sort × 1003text-processing × 173
awk × 134
linux × 115
bash × 110
shell-script × 85
uniq × 74
ls × 67
shell × 62
files × 62
grep × 61
find × 52
sed × 46
command-line × 43
locale × 35
filenames × 33
date × 33
scripting × 22
csv × 22
numeric-data × 20
join × 19
pipe × 18
cut × 17
macos × 16
unicode × 16