Try this - replace echo with actual move when your happy it's working:
Quote:
Originally Posted by vistastar
One line of command is enough:
Well, Chubler_XL's solution could be written on one line if one was so inclined (there's nothing in the shell grammar that prevents it).
Also, the approaches are not equivalent. Chubler_XL's solution can handle any valid filename (if $file after mv is quoted), regardless of how ludicrous it may be. Your approach, however, could be wrecked by field splitting and pathname expansion after the command substitution, if any of the filenames contain IFS characters (spaces would be the most likely culprit) or glob metacharacters (and asterisks, question marks, brackets).
The -F option to ls will add an asterisk after any shell scripts with an executable bit set (which is to be expected but not a certainty for a .sh file). The grep should probably handle an optional * after .sh.
Lastly, your grep regular expression is underspecified. The ".sh" will not just match names ending in ".sh" but also "ash", "ish", etc. The dot is a metacharacter and needs to be quoted to match itself.
Regards,
Alister
---------- Post updated at 11:17 AM ---------- Previous update was at 11:12 AM ----------
Quote:
Originally Posted by cgkmal
That's incorrect. Bracketed expressions in globs do not work that way. That actually matches any file whose final character is not a "." or and "s" or an "h", and not a file whose name does not end in the string ".sh".
Your approach, however, could be wrecked by field splitting and pathname expansion after the command substitution, if any of the filenames contain IFS characters (spaces would be the most likely culprit) or glob metacharacters (and asterisks, question marks, brackets).
This approach also has issues when no *.sh files exist, or when too many exist and the command line limit is exceeded.
Last edited by Chubler_XL; 04-04-2011 at 11:30 PM..
Hey guys,
I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output)
#!/bin/bash -l
#SBATCH -p node
#SBATCH -A <projectID>
#SBATCH -n 16
#SBATCH -t 7-00:00:00
#SBATCH --mem=128GB
#SBATCH --mail-type=ALL... (1 Reply)
I am trying to find files that have lines in them that end in an r. I have been able to locate files by using the following command:
find . -type f -name "*RECORDS"| xargs grep -l r$
However, I now want to find files that don't end in r anywhere. That means that no sentences or lines in... (9 Replies)
I want to move all files from one directory to another directory excluding today (sysdate files) on daily basis.
file name is in pattern file_2013031801, file_2013031802 etc (2 Replies)
Hi Unix Gurus,
I need to list all files in a Unix Directory which either end with a
.pdf or .rtf and they should be case insensitive ie .Pdf , .pDF , .RtF etc are also possible.
How can i accomplish this with with a ls command ? If not then a find command. (6 Replies)
I am trying to check if files staring with filename but ending with diffent dates e.g. filename.2011-10-25.
The code I am using is below
if
It works find only if one file is present but returns binary operator expected
when there are mulptiple files.
Please help me correcting it. I... (5 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
how to display a listing of all the files ending in txt using one command.
2. Relevant commands, code,... (4 Replies)
I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find )
The directory structure looks like :-
/tmp
a.log
b.log
c.log
/abcd
d.log
e.log
When I tried the following command , it movies all the log files... (8 Replies)
Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder.
thanks (5 Replies)
Hi,
I am a newbie to shell scripting. here is my objective:
1)The shell program should take 2 parameters - ie-> DestinationFolder, WebFolder
2)Destination folder contains few files that has to has be verified and deleted.
3)WebFolder is a folder containing a list of master files
4)It... (1 Reply)