Created
December 16, 2014 15:32
-
-
Save ddouhine/f0d97b8b4a7f17edaa3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replace: | |
sed -e 's/oldtext/newtext/g' | |
Removing the last three characters from every filename | |
cat files | sed 's/\(.*\).../\1/' | |
Removing first character from each filename/string | |
cat files |sed 's/.\(.*\)/\1/' | |
Removing last character from each filename/string | |
cat files |sed 's/\(.*\)./\1/' | |
Delete line feed: | |
sed ':a;N;$!ba;s/\n/ /g' | |
dos2unix: | |
tr -d \\r < win.txt > unix.txt | |
unix2dos: | |
sed -e 's/$/\r/' < unix.txt > win.txt | |
Print first field: | |
awk '{print $1}' file | |
Print first field using a delimiter: | |
awk -F ";" '{print $1}' file | |
Print last field using a delimiter: | |
awk -F "/" '{print $NF}' file | |
Print 3 first fields of an ip address: | |
cut -d '.' -f 1-3 | |
Print only strings with >=8 char: | |
awk 'length>=8' | |
Print IP addresses: | |
grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | |
egrep "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]" | |
Print the beginning of a string: | |
grep '^xxx' file | |
Print the end of a string: | |
grep 'xxx$' file | |
Print 3 lines before the match: | |
grep -B 3 string file | |
Print 3 lines after the match: | |
grep -A 3 string file | |
Don't print the 2st char: | |
cut -c3-10 | |
Don't print empty lines: | |
grep -v "^$" | |
Sum of numbers on multiple lines: | |
tr -d \\r | paste -sd+ | bc | |
Sort by string size: | |
sort -n | |
Merge columns of 2 files: | |
paste -d' ' file1 file2 | |
pr -mts' ' file1 file2 | |
sed -e 's/ //g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment