Git Product home page Git Product logo

regex's Introduction

Regex Tips

Change extension.

find . -name '*.txt' | sed 's/.*/mv & &/' | sed 's/\.txt$/.tec/'

Random number generator.

echo $(( $RANDOM % 100))

Find a specific line.

cat lista.txt | sed -n 3p


Regex IPv4

([0-9]{1,3}(\.[0-9]{1,3}){3})

Regex IPv6

([a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})

Change key with extension .PPK (PUTTY) to Linux Format

for X in *.ppk; do puttygen $X -L > ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pub; puttygen $X -O private-openssh -o ~/.ssh/$(echo $X | sed 's,./,,' | sed 's/.ppk//g').pvk; done;

Add "/32" in the last line.

sed 's/$/\/32/'

Add the "set address office365-" in front line and change "." to "-", finally with "--32".

sed 's/^/set address office365-/' | sed 's/\./-/g' | sed 's/$/\--32/'

Remove line with that have "/"

sed '/\//d'
ex.:
192.178.10.20/23

sed 's:\/:--:g' FILE.txt | sed 's:\.:-:g'

Remove empty line.

sed

'/^\[\[:space:\]\]*$/d'
'/^\s*$/d'
'/^$/d'
-n '/^\s*$/!p'

grep

-v '^$'
-v '^\s*$'
-v '^\[\[:space:\]\]*$'

awk

/./
'NF'
'length'
'/^[ \t]*$/ {next;} {print}'
'!/^\[ \t\]*$/'

Find out users that content name with "." in file.

Ex: "carlos.jose"
sed -n '/\./p' usuario | uniq

Change from line to column, or from column to line.

:%s/,/\r/g

change (,) to next line.

sample.
teste1,teste2,teste3,teste4,teste5
to:
teste1
teste2
teste3
teste4
teste5

the other way around.

:%s/\n/\,/g

teste1
teste2
teste3
.
.
.
to
teste1,teste2,teste3 ...

Add "#" or something in some line range on Vim editor.

:start line,last line/^/#
Sample:

:4,10s/^/something

image

to

image


Files chi

[^\x00-\x7F]+\ *(?:[^\x00-\x7F]| )*.exe

URL Validation

[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

Ip Address

\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b

Timestamp

^((([0-1]?[0-9])|([2][0-3])):)?(([0-5][0-9]):)?([0-5][0-9])(\.\d{1,3})?$|^\d+(\.\d{1,3})?$

Extensions (used in AntiSpam Symantec)

(\.\+w|.js|.exe|.doc|.txt|.rar|.tar|.pdf|.img|.xlsx$)

Content in URL

(.ttp[s]?\:.*(.php|.zip|.bat|.exe|.src|.run\$))
([^Received:]\s+(.*from\s).*)(\.sebraego.com.br)

Content "From in first line and jump (\n+) searching for google.com"

((.*From.*[\n+].*)google\.com.*)

Match all domain below

.*\.(ly|cn|kp|ira|fy|af|ss|cu|iq|il|ye|ir|ru).*

Match the last URL content https/http

(.*tps?:\/\/.*(\.exe|\.vbs|\.php|\.sh|\.jar|\.zip|\.bat|\.js|\.cmd|\.src$))
(.*tps?:\/\/.*(\.php|\.sh|\.cmd|\.exe|\.bat|\.vbs|\.jar|\.js|\.src|\.aspx).*)
(.*tps?:\/\/.*(\.exe|\.vbs|\.php|\.sh|\.jar|\.zip|\.bat|\.js$))

Match all content below

(.*www-data@.*)|(.*@localhost.*)

Match all words and number including code font.

(.*[\d]@.*)

Match all phrases that content "clique" or "clique aqui"

(.*tps?:\/\/)(.*[Cc]lique?.*aqui|.*[Cc]lique$)

CPF

([0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2})

Match in words that content "$"

(\w+.?[\$]) ou (\w+[\$])
\w+[\$]|((SRV)\w+)|((srv)\w+)
SRVLAV$ or $SRVLAB or SRVLAB or srvLaB
(\w+[$]|[$]+\w+)

Remove "," and jump to next line

sed 's/,/\n/g'

Find out string or anything using "|" with grep command

cat malware | grep -Ev "micros|google|sebrae|linke|skype|portaldoem|facebook|gov.br|icloud|footprintdns"


Get Details about some Malware IP

curl --request GET --url 'https://www.virustotal.com/vtapi/v2/ip-address/report apikey=1e73f5e9573b8a85a9f4118b39071a9d3f89849ab98f935bc611e5b457bf8e9f&ip=209.99.40.222'

{"last_resolved": "2015-09-18 00:00:00", "hostname": "019582.yihedu.com"}

cat file1  | sed 's/,/\n/g' | grep hostname | awk '{print $2}' | sed 's/\"}//' | sed 's/\"//'
cat file1  | sed 's/,/\n/g' | grep url | awk '{print $2}' | sed 's/\"//' | sed 's/http\:\/\///' | sed 's/\/.*//' | sort -u

add "*" in the start line

sed 's/^#*/*/' 

add "*" in the last line

sed 's/$/*/'

Remove the empty line with SED

cat file.txt | sed '/^$/d'

Get IP information using the VirusTotal API command

curl --request GET --url 'https://www.virustotal.com/vtapi/v2/ip-address/report?apikey=1e73f5e9573b8a85a9f4118b39071a9d3f89849ab98f935bc611e5b457bf8e9f&ip=209.99.40.222' | sed 's/},/\n/g' | grep url | awk '{print $2}' | sed 's/\"//' | sed 's/http\:\/\///' | sed 's/\/.*//' | sort -u | sed 's/^#*/*/' | sed 's/$/*/'

Remove "^M"

sed -e "s/\r//g" file > newfile
ou
dos2unix script

How to convert a string from uppercase to lowercase

cat file.txt | tr '[:upper:]' '[:lower:]'

Anything

(^DWM|^DicomServer|^DefaultAppPool|^schedule.tasks|^AppVPublishing|^Symantec|^postgres|^Classic|^synapseae|^altaperformance|^.NET\s)|(\w+[$])

lynx --source https://ransomwaretracker.abuse.ch/ip/209.99.40.222/ | awk {'print $3}' | sed 's/href\=\"host\///' | sed 's/\/\"//'

Links

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.