Replace the line in all files - Unix

I am trying to replace the string ::: with :: for all the lines in the txtfiles package (it can be considered as a word, since it is always in front and behind it.

I can do this with python as shown below, but is there a less "over" / confusing way to do this through a unix terminal? (many channels allowed)

 indir = "./td/" outdir = './od/' for infile in glob.glob(os.path.join(indir,"*")): _,FILENAME = os.path.split() for l in codecs.open(infile,'r','utf8').readlines(): l = l.replace(":::","::").strip() outfile = codecs.open(os.path.join(outdir,FILENAME),'a+','utf8') print>>outfile, l 

Then I move all the files from od to td mv ./od/* ./td/*

+7
source share
2 answers
 find . -name "./td/*.c" -exec sed -i "s/:::/::/g" '{}' \; 

No need for od/ at all.

EDIT:

A slightly simpler variation:

 ls td/*.c | xargs sed -i '' "s/:::/::/g" 
+18
source

A simple loop to process each file with sed should be sufficient.

 for inp in ./td/*; do fname=${inp##*/} sed 's/:::/::/g' "$inp" > ./od/"$fname" done 
+3
source

All Articles