MySHELL

From pressy's brainbackup
Jump to: navigation, search

MySHELL Section

Well, you could use your shell, or you can use your shell ;) Some One-Liners and Commands...


rename files with the same format

# ls
1.jpg  10.jpg  100.jpg
# for INPUT in *.jpg; do mv $INPUT `printf %04d $(basename $INPUT .jpg)`.jpg; done
# ls
0001.jpg  0010.jpg  0100.jpg

SuperGrep

Search for a string and print the line

# awk '/name/ {print $0}' file

Search for a string, but print the line above

# awk '/name/ {print x};{x=$0}' file

Search for a string, but print the line afterwords

# awk '/name/ {getline;print}' file

Search for a string, but print the lines above and afterwords, where a is after.

# nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}'  b=2 a=2 s="pressy" file

Play with your variables

# echo $X
eins.zwei.drei
# echo ${X#*.}
zwei.drei
# echo ${X%.drei}
eins.zwei
# echo ${X/zwei/vier}
eins.vier.drei

TERM Colour

# echo "\0033[31;1m rot \0033[34;1m blau \0033[32;1m grün \0033[31;0m nix"