2021年4月29日星期四

How to copy filename up to specific characters (and add the copied text to the top of the same file)

I'm updating a bash script (for Mac) that I have not looked at in a while and I want to copy the characters of a filename up to __ (two underscores). What I have currently grabs the first 6 characters, and pastes it fine, but I'm not sure how to change it to copy everything up to the first two underscores (not _ or a single underscore).

#This copies the first 6 characters of the FILENAME   #and adds it to the top of the same file  #!/bin/bash  for filename in ./*.txt  do      text="${filename:2:6}"      echo $text | cat - $filename > temp && mv temp $filename;  done;  

Thanks in advance for the help :)

https://stackoverflow.com/questions/67324620/how-to-copy-filename-up-to-specific-characters-and-add-the-copied-text-to-the-t April 30, 2021 at 04:27AM

没有评论:

发表评论