Tag Info

Hot answers tagged

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 ...


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.


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


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


2

With the zsh shell, you can affect the order of globs with glob qualifiers. grep 'exit 0' a*(.Om) Om is to reverse o⃞rder by m⃞odification time. I also added .⃞ to select only regular files (not directories or pipes or devices or symlinks...).


2

You could simplify this significantly (and avoid the nasty problems inherent in parsing ls) by doing something like: file_nm=$(find . -maxdepth 1 -name "*abc*"); [ -e "$file_nm" ] && grep -q "search_txt" "$file_nm" && echo "string found" || echo "string not found" However, like your original example, that will fail if you have ...


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.


1

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


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.


1

If none of the file names contain space, tab, newline, ?, *, [ characters or are called -, this should do it: grep "exit 0" -- $(ls -tr a*) $() is called command substitution. Your shell will first run ls -tr, then use the output as the list of files for your grep command.



Only top voted, non community-wiki answers of a minimum length are eligible