Tag Info

New answers tagged

0

You can use this command: ls /etc/main |xargs du -sk $1 |sort -rn| head -10


3

Use du and sort: du -sk /etc/main/* |sort -nr The arguments -sk to du tell it to report usage in kilobytes, and to sum the size of all the contents of the directory instead of reporting to each file. The arguments -nr to sort tell it to sort numerically and in reverse order so that you get the largest directory first.


0

Gilles's answer is (IMHO) brilliant (as always), but since you didn't choose it or even up-vote it, perhaps you find it too complicated. So here are a few (simple) points that might or might not be helpful, and may help you avoid maintaining two separate scripts, which could turn into madness for a large script that has to be maintained over a long period ...


4

POSIX and Hyphens According to the POSIX standard, a function name must be a valid name and a name can consist of: 3.231 Name In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit. A hyphen is not listed among the characters ...


1

Other possible approach is export a windows share at your windows host (how to to that would be off-topic) and then access it from your linux host using SMB tools like smbclient.


2

Instead of trying to sorting a list of filenames in a particular way, you could just use: ls -1v *.pdb to list the files in the required order in first place.


0

Try: sort -t "_" -k2 -k3 -g <filename> -t "_" - field seperator is _ -k2 - 1st sort on the second column -k3 - then sort on the third column -g - general numerical sort


1

Can do like this : $ cat file.txt | sort -t"_" | sort -n -k3 -t"_" file.txt contain the first list not sorted. Cheers.


0

sort -V -V, --version-sort natural sort of (version) numbers within text


0

Try: sort -t_ -k3n -t_: sets field separator to _ -k3n: sorts on 3rd field numerically (n)


2

If your system doesn't have /dev/stderr (a SysV thing, Linux having a different implementation with caveats), you can use perl that way: { your-code .. } | perl -pe 'print STDERR' perl processes the input one line at a time, so you won't see partial lines there. For instance with code like: printf 'Foo'; sleep 2; printf 'Bar\n' You'll only see ...


2

I don't know whether ksh has a feature to do that. zsh can do it (with the multios feature). But there is a way with tee: echo foo | tee /dev/stderr echo foo | tee /proc/self/fd/2


0

This can be done entirely within the shell, with a case construct. string='Fox juMPed the rock' case "$string" in *[:lower:]*) echo "The string contains lowercase letters.";; esac In ksh, you can use typeset -u to convert a string to uppercase. It doesn't matter whether the original was all-uppercase or not. string='Fox juMPed the rock' typeset -u ...


0

You can use tr to normalize word separators, then grep to print matching words (with the options -Fx to match a string exactly and -i for case insensitivity). tr -cs A-Za-z \\n | grep -Fxi home If you're in a non-ASCII locale, note that many implementations of tr operate on bytes, not characters. Use another tool such as sed to perform the word separator ...


0

Using awk to look for whole words similar to grep -o -w: $ echo "I am going home. Home is where heart is." | awk -v 'RS=[^[:alnum:]_]' -v w="home" 'tolower($0)==w' home Home As Gilles points out, this requires an awk, such as GNU awk, which supports regular expressions for RS.


2

Playing with perl : $ echo 'I am going home. Home is where heart is.' | perl -lne 'for (split /\W+/) {print $& if /\bhome\b/i}' And even shorter, adapted from Joseph R. comment bellow (thanks to him) $ echo 'I am going home. Home is where heart is.' | perl -lne 'print $& while /\bhome\b/ig' Result: home Home


-1

You can iterate over words, grep the specified word and remove punctuation characters $ s="I am going home. Home is where heart is." $ for w in $s; do echo $w; done | grep -Ei '(^|[[:punct:]]*)home([[:punct:]]*|$)' | tr -d '[[:punct:]]' home Home


0

You can use grep -ioE to obtain all matches for a given regexp $ echo "abc jumped def Jumped fgh JUMPED klm" > file.txt $ grep -ioE "j\w+" file.txt > matches.txt $ cat matches.txt jumped Jumped JUMPED Now, you can iterate on the result and remove full lower/upper matches (bash) : $ for w in $(cat matches.txt); do if [[ ! $w == ${w^^} && ! ...


0

Let me make it a little clearer. What I want is to make the keywords in a code file turn in UPPERCASE. In that case, there is no need to test if a word has any lower case letters. It is easier and, in the end, likely more efficient to just replace them all. $ echo Fox Jumped and JUMPED and juMPed the rock | sed 's/jumped/JUMPED/gi' Fox JUMPED and ...


0

Perl can do this fairly easily: $ echo 'Fox juMPed the rock' | perl -pe 's/jumped/\U$&/i' Fox JUMPED the rock It looks for jumped, case insensitive, and replaces it with the uppercase version.


0

printf %s\\n 'juMPEd'| sed 's/[^[:lower:]]//g' OUTPUT jud


-1

printf %s\\n 'I am going home. Home is where the heart is.' | sed 's/\([hH]ome\)*.\{,1\}/\1/g' OUTPUT homeHome


0

using awk: echo "I am going home. Home is where heart is. I dont like Homework." | awk '{for(i=1;i<=NF;i++) {gsub(/[^a-zA-Z0-9]/,"",$i); if(match(tolower($i),/^(home)$/))print $i;}}' output: home. Home


0

SUGGESTION, inspired on the idea of an anonymous pipe, and the need to use the output of a function as the input to an array, I found a co-process can help. MyFunction() { echo "One line" ; echo "Second line" ; echo "Third line" } set -A array MyFunction 'SomeInputToFunction' < /dev/null |& while read -p -r line; do print "READING from ...



Top 50 recent answers are included