copying files and give new unique names to each file by using xargs command
Hello there. Can someone help me. I am trying to copy specific files to current directory and give each of the file a new name by using the xargs command. This is what I have so far but I'm stuck:
ls -l |grep "June"| awk '{print $9}|xargs -ti cp {} |
first of all, this:
ls -l |grep "June"| awk '{print $9}' is wrong. If the files contain any spaces, you'll mess things up. Are you searching for files containing June in the filename? *EDIT* Welcome to LQ forums :) |
Yes I am. The command ls -l just gives out a long listing output of all the files under the current directory I'm in. The output then is what I'm trying to manipulate. In this case, I wanted all the June files to be copied with new names. I was hoping to achieve this with the xargs command.
|
I would use something like this to get the full name:
Code:
find . -type f -name "*June*"| while read filename; do ...... done When you say new names, do you mean random names, specific names, names that follow a pattern (file00 , file01), etc. What exectly do you want? |
Thanks. The new file name will only contain character
14-19 of the original name and with the new extension of .csv Example: rospslpar1_1_050616_0005.nmon (current existing name) 050616.csv (new copied file name) |
Try a simple bash script. Something like this should work. I haven't tested it.
Code:
find . -maxdepth 1 -type f -name "*rospslpar*" |while read filename; do |
Thanks again perfect_circle. This really helps. I'll let you know if it works out or not.
|
All times are GMT -5. The time now is 05:53 AM. |