neeyoo11

Pattern matching (Filename)

May 26th, 2022 (edited)
292
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear
  2. if [ $# -ne 1 ]
  3. then
  4. echo "Invalid number of Arguments"
  5. exit
  6. fi
  7. dir=mydir
  8. if [ -d $dir ]
  9. then
  10. echo "Directory $dir exists"
  11. else
  12. mkdir $dir
  13. fi
  14. echo "The files mathcing the pattern $1 are: "
  15. ls *$1* > filenames.txt
  16. cat filenames.txt
  17. echo "The contents of the files are: "
  18. for i in filenames.txt
  19. do
  20. echo "Filename: $i"
  21. cat $i
  22. cp $i ./mydir/$i
  23. done
  24. echo "The files have been copied into ~/mydir"
  25. cd mydir
  26. ls -l
  27.  
RAW Paste Data Copied