Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2019-08-14 10:44:10
Size: 174
Editor: PieterSmit
Comment:
Revision 5 as of 2020-04-04 07:11:57
Size: 832
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe Linux/FindGrepAwkSed here. ## page was renamed from Linux/FindGrepAwkSed
Describe Linux/FindGrepAwkSedXargs here.
Line 5: Line 6:
 * [[regex]] only part of grep match returned

== Search dir for files containing string and replace all of them ==
{{{
##e.g. search for tentant -> tenant
grep -irlZ 'tentant' ./ | xargs -0 sed -i 's/tentant/tenant/g'
}}}

== Bash loop over files ==
 * Rather than using find and xargs, use globing to find and process files in bash
   * e.g. {{{
#By enabling the globstar option, you can glob all matching files in this directory and all subdirectories:
# Make sure globstar is enabled
shopt -s globstar
for i in **/*.txt; do # Whitespace-safe and recursive
    process "$i"
done
}}}

Describe Linux/FindGrepAwkSedXargs here.

Find files containing something in Linux

Search dir for files containing string and replace all of them

##e.g. search for tentant -> tenant
grep -irlZ 'tentant' ./ |  xargs -0  sed -i 's/tentant/tenant/g'

Bash loop over files

  • Rather than using find and xargs, use globing to find and process files in bash
    • e.g.

      #By enabling the globstar option, you can glob all matching files in this directory and all subdirectories:
      # Make sure globstar is enabled
      shopt -s globstar
      for i in **/*.txt; do # Whitespace-safe and recursive
          process "$i"
      done


CategoryLinux

Linux/FindGrepAwkSedXargs (last edited 2024-01-24 20:48:46 by PieterSmit)