Skip to content

tastywheat/nix-command-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 

Repository files navigation

nix-command-patterns

Search and replace

grep -rl components2 . | grep .js$ | xargs sed -i '' 's/components2/components/g'
  • grep, (r) recursive, (l) pathname only
  • grep only .js files
  • xargs to enumerate input
  • sed to edit file in place

Find by file extension

find . -name "*.js"
  • recursive
ls . | grep .js
  • non-recursive
grep --include=*.js 'sometext' somedirectory
  • using include

Interpolate template file

// tempalte.txt
${FIRST_NAME} ${LAST_NAME}
...

sed -e "s/\${FIRST_NAME}/tasty/g" \
    -e "s/\${LAST_NAME}/wheat/g" \
    template.txt > DESTINATION_FILE

Inject line into file below target

// somefile.txt

/* START_HERE */

...

sed -i '' '/START_HERE/a\
    import _ from 'lodash';\
    ' somefile.txt

Lowercase an uppercase letter with perl

echo "fooBar" | perl -pe 's/([A-Z])/\l$1/g'
  • perl expression must use single quotes

List files with tr and cut

ls -l | tr -s ' ' | cut -d ' ' -f 9
  • tr will squash spaces
  • cut to split on space, and select column 9

About

*nix command patterns

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published