Advertisement
dzocesrce

[OS] Numerical Names

Jan 21st, 2024
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.70 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -ne 2 ]
  3. then
  4.     echo "USAGE: `basename $0` source_folder some_name.txt"
  5.     exit 1
  6. fi
  7. FROM=$1
  8. result=$2
  9. #recursively list even the deepest documents in the argument#1 folder, then leave only the names of the .txt files that include a \n1n2n3n4\ pattern
  10. files=`ls -R $FROM | grep ^- | awk 'print $9' | grep \'\'[0-9][0-9][0-9][0-9]\'\'.*\.txt$`
  11. for f in $files
  12. do
  13.     #get the 4 digit number in the file's name and print the file's insides in the argument#2 file
  14.     digitcode=` echo $f | awk -F'\' {print $2}`
  15.     echo "============= $digitcode ============="
  16.     echo "cat ${FROM}${f}" >> $result
  17.     echo "============= $digitcode ============="
  18. done
  19. cat $result
  20.    
  21.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement