GithubHelp home page GithubHelp logo

useful-one-liners's Introduction

Useful-one-liners

A collection of useful one liners that I have collected over time to help in extracting data, formatting data etc. Still a work in progress!

Extract email addresses from any/most files. Mostly used against .txt, html, json files.

Extract unquoted paths that contain a space.

Syntax: grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" filename.json | uniq

Example of data within file we want to extract.

cat users.json
{
  "nodes": [
    {
      "id": 400,
      "type": "User",
      "label": "[email protected]",
      "props": {
        "highvalue": false,
        "sidhistory": {},
        "passwordnotreqd": false,
        "description": "Service Accounts",
        "sensitive": false,
        "unconstraineddelegation": false,
        "pwdneverexpires": false,
        "enabled": true,
        "hasspn": false,
        "domain": "umsundu.com",
        "pwdlastset": 13607787938,
        "displayname": "bob-324KL",
        "name": "[email protected]",
        "lastlogon": -1,
        "distinguishedname": "CN=bob-324KL,OU=*****,DC=umsundu,DC=com",
        "serviceprincipalnames": {},
        "admincount": false,
        "lastlogontimestamp": -1,
        "objectid": "S-1-5-2*********************",
        "dontreqpreauth": false
      },
         {
      "id": 401,
      "type": "User",
      "label": "[email protected]",
      "props": {
        "highvalue": false,
        "sidhistory": {},
        "passwordnotreqd": false,
        "description": "Service Accounts",
        "sensitive": false,
        "unconstraineddelegation": false,
        "pwdneverexpires": false,
        "enabled": true,
        "hasspn": false,
        "domain": "umsundu.com",
        "pwdlastset": 13607787938,
        "displayname": "sue-322JL",
        "name": "[email protected]",
        "lastlogon": -1,
        "distinguishedname": "CN=sue-322JL,OU=*****,DC=umsundu,DC=com",
        "serviceprincipalnames": {},
        "admincount": false,
        "lastlogontimestamp": -1,
        "objectid": "S-1-5-2*********************",
        "dontreqpreauth": false
      },

Example of running query against the file to extract email addresses.

grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" users.json | uniq
[email protected]
[email protected]

Extract unquoted paths that contain a space.

Syntax: grep -oP '^[^"]*\s[^"]*$' filename.txt

Example of sample file containing quoted paths with a space and unquoted paths with a space.

We want to extract only the unquoted paths that contain a space from the below list.

"C:\Users\Public\Old Desktop\tool.exe"
C:\Users\Public\Old Libraries\here.exe
"C:\Program Files\yes\321 123\testing.exe"
C:\ProgramFiles\btest\boom\boom.exe
C:\Program Files\KeePass Password Safe 2\XSL
C:\Program Files\btest we\boom\boom.exe
"C:\Program Files\yes\all good\good.exe"

Running grep with the regex to extract only the paths that are unquoted and contain a space.

grep -oP '^[^"]*\s[^"]*$' test.txt
C:\Users\Public\Old Libraries\here.exe
C:\Program Files\KeePass Password Safe 2\XSL
C:\Program Files\btest we\boom\boom.exe

useful-one-liners's People

Contributors

umsundu avatar

Watchers

Kostas Georgiou avatar  avatar

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.