Last active
July 27, 2018 13:51
-
-
Save renatocassino/f1b5c07fa2057e126ab8bfb2bc0c3b48 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
# Show only ids to an especific id | Possible commands | |
docker ps -a | grep mongo --color | sed -e 's/^\([a-z0-9]*\).*/\1/' # With grep | |
docker ps -a | sed -n /mongo/p | sed -e 's/^\([a-z0-9]*\).*/\1/' | |
docker ps -a | awk '/mongo/ {print $1}' # Using AWK | |
# Download list of m4a from an xml via curl | |
wget -i $(curl http://vip.aersia.net/roster.xml\?296 | sed -e '/location/!d' -e 's/\<location\>\(.*\)\<\/location\>/\1/g' -e 's/^[^a-z]*//g') | |
# Insert with sed | |
sed '/regex/i\ | |
Text to put insert' | |
## Replace and create a backupt file | |
sed -i.bak 's/name/Name/g' file.txt | |
# File file.txt.bak is created | |
## Insert in line number | |
sed '1 i\ | |
Text to insert' | |
# Append test | |
sed '/regex/a\ | |
Text to append' | |
# Change line | |
sed '/regex/c\ | |
Change full line' | |
# Search without "---" but with "--" | |
sed '/---/!s/--/>>/g' | |
# -- to >>, but if --- does not change | |
# -n command | |
sed -n 's/nice/Nice/p' list # Getting word nice, change to Nice and print (not replace in file) | |
sed -n 's/nice/Nice/' list # Cannot print and dont replace | |
# http://www.grymoire.com/Unix/Sed.html | |
# https://www.gnu.org/software/sed/manual/sed.html#Invoking-sed | |
# Change any letter with y | |
sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' # must has the same length of chars | |
# Command write (depends a file) | |
# Sintax: sed -n '/pattern/w outputfile.txt' inputfile.txt | |
# In a list of links, get only with '99spirits' text | |
sed -n '/99spirits/w list' listoflinks | |
cat list # Show only links with 99spirits | |
# Command with comma | |
# Comma get text between two expressions | |
sed -n '/BEGIN/,/END/p' # Will print only content between BEGIN and END | |
# Command read (depends a file) | |
# file: list_of_links -> has a list of links | |
# file: text_file -> has a text | |
# Change the linke __LINKS__ in a text_file | |
sed -e '/__LIST__/r text_file' list_of_links | |
# Hold command | |
# The hold command keep an match in memory and u can use after | |
# After hold, u can use the command (G|g) to append before and x to swap line | |
# The difference between the lowercase and uppercase versions of the same command is that the lowercase command overwrites the contents of the target buffer | |
# Ex: In a text, replace "the (something here) statement is awesome" - Put (something here) in uppercase. | |
# Create an lorem ipsum text and choose onde line and insert: the match statement is really awesome | |
# Script | |
/the .* statement/{ | |
h | |
s/the \(.*\) statement.*/\1/ | |
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ | |
G | |
s/\(.*\)\n\(the\).*\(statement\)/\2 \1 \3/ | |
} | |
$ sed -f myscriptfile mytextfile | |
# 1st step - Search the string | |
# 2nd step - hold the match | |
# 3rd step - get the word that will be replaced to uppercase | |
# 4th step - change to uppercase | |
# 5th step - G command will place the hold script before the match line | |
# 6th step - Get the G command with a breakline and the original phrase and change the order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment