Skip to content

Instantly share code, notes, and snippets.

@estysdesu
Last active July 21, 2019 08:54
Show Gist options
  • Save estysdesu/5aa6a31b7ea346a94826504a4889d6ef to your computer and use it in GitHub Desktop.
Save estysdesu/5aa6a31b7ea346a94826504a4889d6ef to your computer and use it in GitHub Desktop.
[Shell: text/file modification] #grep #tr #sed #awk #cut #sort #sh #chmod
##### tr (TRANSLATE/DELETE) #####
# tr <pattern-translate-in> <pattern-translate-out>
# -d: delete SET1
# -t: truncate SET1 to length of SET2
# -c: compliment SET1
# -s: squeeze the repitition SET1
tr 'a-z' 'A-Z' < <file> # converts input to all caps
tr -d ' ' < <file># delete spaces
cat <file> | tr -cd [:digit:] # delete all but digits
##### cut #####
# -d: delimiter
# -f: fields (`-f1-7` or `-f1,3,8`)
# -c: chars (`-c1-11,50-`)
ls -l | cut -c1-11,50-
##### grep (PATTERN SEARCH, REGEX) #####
# --color: colorize the match location
# -c: count number of lines that match
# -n: line nos. that match
# -v: invert match
# -i: ignore case
# -e: expression (useful for multiple patterns)
# -E: extended regex (acts like `egrep`)
grep --color -c bash /etc/passwd
##### sort #####
# -r: reverse the result of comparisons
# -t: delimiter (`,`, `' '`, `:`)
# -f: ignore case
# -b: ignore leading blanks
# -d: dictionary sort
# -n: numeric sort
# -k: field to sort by
# -u: unique
sort -t, -k2 -k1n -k3 <file> # sort field2 as primary, field1 numbers as secondary, and field3 as tertiary
##### nl (LINE NUMBERS) #####
cat <file> | nl # outputs file contents with line nos.
##### chmod (PERMISSIONS) #####
# a: add permissions
chmod a+x <file> # add execute permissions to file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment