Your code gives me the following result
I could able to google to change it in one line.
The echo above works fine. So I changed it to the following
I like to use the above mv command along with sed in find itself.
Then your input is different from the example you gave, which doesn't have absolute paths at all ("find . ..."). I suggest you consult the man page of "ksh" or "bash" about "variable expansion" and modify my code accordingly to get the results you want.
Your solution is quite inefficient as well as inherently dangerous, because:
Quote:
Originally Posted by bobbygsk
This will not work once the path name of the file contains spaces or more than one period character, both perfectly legal possibilities. In addition, the backticks are deprecated and the whole construction with an external program ("sed") which is fed another process ("echo ...|") will consume 2 fork()s for every single file (and the backticks a 3rd fork()), which is quite taxing in terms of resources: memory and CPU time.
Quote:
Originally Posted by bobbygsk
So I changed it to the following
This adds even more external calls and the expansion in the subshell ("$(...)") at the head of the for-loop will break once the number of files reach a certain limit. The reason being the way the shell evaluates input lines: subshell substitutions like yours are first executed in a subshell, then their result (=output on stdout) is replaced for them. If your "find" creates a long list you eventually hit the maximum number of characters for input lines, which is a kernel constant (MAX_LIN) defined in "/usr/sys/include/limits.h".
I suggest replacing the for-loop with a while-loop and a pipeline if you insist doing it this way, better yet, do it like i suggested.
Hi,
I have a test.zip archive that contains
test.zip --> (file_1.txt, file_2.txt , file_3.txt)
I need to unzip the file like this,
file_1_timestamp.txt
file_1_timestamp.trg
file_2_timestamp.txt
file_2_timestamp.trg
file_3_timestamp.txt
file_3_timestamp.trg
Could you please let me know... (7 Replies)
Hi,
In my previous post I looked for timestamp to be added to the filename
https://www.unix.com/shell-programming-scripting/230603-how-append-timestamp-filenames-using-find.html
Now how do I select those files that do not have timestamp in the filenames.
I tried the following. My file has... (3 Replies)
I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example
... (13 Replies)
I have a group of files in different directories with characters such as " ? : in the file names. How do I find these files and remove these characters on mass?
Thanks (19 Replies)
Hi,
I want to check all files in a folder for some specific start string and append all matching filenames with _1, _2 .... for each file found in the directory.
But, $file below gives me all details of the files like access permissions, owner and filename etc. I just want all the filenames... (3 Replies)
I have the following code:
find /usr/local/test5 -type f -mtime +30 -exec ls -l {} \; | awk '{print $5, $6, $7, $8, $9}'
I have this as output:
14 Aug 12 00:00 /usr/local/test5/file1
14 Aug 12 00:00 /usr/local/test5/lastname,
The bolded part is where I run into trouble. The actual... (4 Replies)
I've setup a cron job that greps a file every five minutes and then writes (appends) the grep output/result to another file:
grep "monkey" zoo.log | tail -1 >> cron-zoo-log
Is there any way I can add the date and time (timestamp) to the cron-zoo-log file for each time a new line was added?
... (12 Replies)
Hi,
I am having set of files whose names are stored in a file say "filelist.txt"
Now, I want to find all files contained in "filelist.txt" from my parent directory.
Is there any way to let find command understand "filelist.txt" just like we have option -f in awk.
I donot want to run a... (4 Replies)
Hi,
I need to write a small script to search in some specific directories to check if any file is present with a unix command name...
Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file.
Please help
Thanks,
D (6 Replies)
How do I write the command to find all files with any lower case letters in the filename? I have tried
find . -name *\(a-z\) and a lot of combinations like that, without success.
thanks
JP:confused: (4 Replies)