Contents
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
$BASEIN is the base folder of your complex structure that you want to copy from
$BASEOUT is the base folder that you want to copy to
-type f specify that you only want to copy regular files in this example thus not including eventual symlinks
-name \*.slcio is the pattern you want to look for in your file. Remember to escape the *.
xargs converts the newline separated output of find in a space separated list that is fed to cp