Easy enough making this pattern-based in sed:
sed 's#/[0-9]*/#//#g' input.txt
This matches any stretch of zero or more digits between two slashes, and replaces the whole bundle with two slashes.
In awk, you might do the same thing this way:
awk '{gsub(/\/[0-9]*\//,"//")} 1' input.txt
The gsub()
command is documented on the awk man page. The 1
at the end is a shortcut for "print this line". But you might alternately treat the fields as actual fields:
awk '{for (i=2;i<=NF;i++) {split($i,a,"/"); $i=sprintf("%s//%s",a[1],a[3])} } 1' input.txt
This is more technically "right" in that it treats fields as fields, then treats subfields as subfields. But it'll undoubtedly be slower than the other options, and will also rewrite lines with OFS as field separators.
Lastly, you could use bash alone, without awk or sed:
shopt -s extglob
while read; do echo "${REPLY//\/+([0-9])\////}"; done < input.txt
This works in bash version 3 (since you're using macOS). It reads each line of input then uses Parameter Expansion to make the same translation that was done in the first two options. This solution is likely slower than the others. The extglob
shell option is used to make more advanced patterns possible.