Tag Info

New answers tagged

3

I think this is POSIX default behavior as stated in man page: -k field_start[type][,field_end[type]] shall define a key field that begins at field_start and ends at field_end inclusive, unless field_start falls beyond the end of the line or after field_end, in which case the key field is empty. A missing field_end shall ...


0

You can use an associative array on awk and then sort: cat access.log | awk ' { tot[$0]++ } END { for (i in tot) print tot[i],i } ' | sort output: 1 c.php 1 d.php 2 b.php 3 a.php


1

The GNU sort documentation for the -t option says By default, fields are separated by the empty string between a non-blank character and a blank character. By default a blank is a space or a tab, but the LC_CTYPE locale can change this. POSIX says If -t is not specified, <blank> characters shall be used as default field separators; each maximal ...


1

cat file: 22 z there's a moose loose in the hoose eg. Set args to: loose moose - read by script as "$@" You can use as many as you like. by=( "$@" ) nl file | sed -nf <(for ((i=0;i<${#by[@]};i++)) ;do echo "s/.*${by[i]}.*/$i\t&/; t p" done; echo "s/^/$i\t&/; :p p") | sort -nk1 -nk2 | ...


2

With sqlite and ORDER BY clause: $sqlite3 <<\EOT CREATE TABLE file(line); .import file.txt file SELECT * FROM file ORDER BY CASE WHEN line LIKE '%USB%' THEN 0 WHEN line LIKE '%Realtek%' THEN 1 ELSE 3 END; EOT 00:10.0 USB controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 81) 00:10.1 USB controller: VIA Technologies, ...


5

It sounds like you want a scoring system.  Write a script to assign a score to each line, indicating how early in the output you want to see it.  awk seems well suited to this job.  For your example: #!/bin/sh awk '{score=0} /usb/ {score=1} /Plantronics/ {score=2} {print score, NR, $0}' "$@" This assigns a score of 0 to every line by default, ...


2

What you're doing isn't really sorting, but selecting. So what you'd want to do is first select all the lines that contain "Platronics", then all the lines that contain "usb", and so on, and finally all the lines that don't match anything. I don't know of a command that does this in one go, but you can write a little script using python that does what you ...


0

I see there is no answer, so my suggestion sort -k2,2 -nk3,3 file


5

FreeBSD and GNU sort have a -V option for that. sort -V < filename GNU ls has a -v option. So if those files do exist, you could do: xargs -d '\n' < filename ls -dv -- zsh has parameter expansion flags to sort arrays numerically: printf '%s\n' ${(fno)"$(<filename)"} Otherwise, portably, you'd have to do it like: sort -t_ -k1,1 -k2,2n ...


1

-V does exactly what you want. -V, --version-sort natural sort of (version) numbers within text Works at least in GNU sort.


1

Since you don't seem to need the filenames you can use -p to output the content of the zip files: (for i in ./*.zip; do unzip -p "$i"; done; cat ./*.log) | grep -F ERROR | sort or if the files errors.zip are all over the place: (find . -type f -name "*.zip" -exec unzip -p {} \; find . -type f -name "err*.log" -exec cat {} + ) | grep -F ERROR | ...


0

Nobody's answering, so this is what I did: sort -T /mnt/tmp --parallel=14 -S 50G myBigFile.txt I didn't use --batch-size as I wasn't sure what would be a good value and presumably sort is clever about it anyway. /mnt is mounted on a big ephemeral disk (the machine is a VM in the cloud). If /tmp is on a disk with plenty of space, you could leave out -T. ...


1

Making an answer from my comment: I had the same problem when I used /run/shm as my /bigdisk for storing sort temp files. /run/shm is a ram disk, so when sort needed to cache partial results on disk (which it does when memory is almost full), memory ran out. The kernel killed sort, as it was the process using the most memory. Using a location stored on ...



Top 50 recent answers are included