sort

sorting by other than first column

use the -k option:

ls -ltr | sort -k 10

sorts by the data in column 10

sed

escaping slash (/) character in sed

simply use

sed -e 's|fsdkfsd/fsdfsd/fdsfs|blablaa|g'

instead of

sed -e 's/fsdkfsd\/fsdfsd\/fdsfs/blablaa/g'

sed uses the first character after the command identifier (in this case s) as a separator for the internal arguments of the command.

grep

searching for A or B

use egrep:

egrep "A|B" <whatever

read

working on single columns of an ascii file (zsh):

cat myfile.csv | while read -A columns; do echo column[0]==$column[0]; done

for bash:

cat myfile.csv | while read -a columns; do echo column[0]==${column[0]}; done

copying and moving

Copying a subset of file in a complex directory structure keeping the subfolders

Cp has a not well known option --parent that copies the whole folder structure of the wanted file to a destination. This can be used together with find to copy all the file that match the find selection parameter into a destination folder.

For example assuming one wants to copy all and only the .slcio file contained in an arbitrarily complex folder structure keeping the folder structure one can use the following command (zsh and bash):

find $BASEIN -type f -name \*.slcio | xargs cp --parent -t $BASEOUT  


CategorySoftware

SHELLtips (last edited 2012-10-15 12:50:05 by StefanoCaiazza)