-
Perl one liner executing a shell command on…
powerful Perl one liner executing a shell command on files. e.g. copy all *.c files to new names, *.R. perl -de ‘foreach (@ARGV) {($new = $_) =~ s/c$/R/; system(“cp $_ $new”);}’ *c
-
Diff sort output diff
sardonically Diff sort output. diff
-
Select random contents from a file Sort sort…
Select random contents from a file Sort sort -R infile | head -n 3000 Perl perl -n -e ‘print if (rand > 0.1)’ infile
-
Display file system status in Unix stat
Display file system status in Unix stat
-
Find files and show the content recursively in…
Find files and show the content recursively in unix. find . -name “readme” -exec head {} \; find . -name “readme” | xargs head
-
Find duplicate or unique records in unix sort…
Find duplicate or unique records in unix sort is essential because uniq find successive identical lines. Unique records cat data.txt | sort | uniq Duplicate records cat data.txt | sort | uniq -d
-
Display file contents with file names tail +1…
Display file contents with file names; tail +1 many_files* It works on Mac, BSD. For GNU tail, use tail -n +1 many_files* Update: GNU tail has different parameters. http://stackoverflow.com/questions/5917413/cat-multiple-files-but-include-filename-as-headers
-
Defining Macros on the Command Line Macros can…
Defining Macros on the Command Line Macros can be defined on the Make command line. For example: make CFLAGS=–ms would start up Make and define the macro CFLAGS with the value “–ms”. Macros defined on the command line take precedence over macros of the same name defined in the makefile. If a command-line macro contains…
-
Rename multiple files on Linux If you are…
Rename multiple files on Linux If you are lucky to have rename installed on your system, use it. Rename is a Perl program and can take Perl regular expression. rename ‘s/^comp/compare/’ *pdf Or copy the code below. http://www.perlmonks.org/?node_id=632437 #!/usr/bin/perl -w # # This script was developed by Robin Barker (Robin.Barker@npl.co.uk), # from Larry Wall’s original…
-
Sort files according to the creation time on…
Sort files according to the creation time on Unix Sort by the last saved time ls -ltr Sort by the created time ls -lUr