- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: problem with "-"
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 01:36 PM
тАО05-25-2005 01:36 PM
Am creating a script that would list and check the files. Some files created have the dash (-) as the first character in the file.
Herewith is part of the script:
ls -la *.res |awk '{print $9}' |while read FILE
do
product=$(awk -F "|" '/^Product/ {print $2}' $FILE|awk -F " " '{print $1}')
if [ $product = "\-" ]
then
$Exepath/mv -f $FILE $temp
fi
done
exit
How and what options should i used to list and moved the files correctly?
maximum points to all correct replies.
Solved! Go to Solution.
- Tags:
- option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 03:02 PM
тАО05-25-2005 03:02 PM
Re: problem with "-"
You could also use find instead of ls,
find /path -name "-*.res" |while read FILE ...
Hope this helps,
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 03:15 PM
тАО05-25-2005 03:15 PM
Re: problem with "-"
I was thinking the filename began w/ a "-" and not the contents of the file.
for FILE in `find /path -name "*.res"`
do
if [ "`head -1 $FILE`" = "-" ];then
mv $FILE $TMP/$FILE
fi
done
and I'm sure there's a million other ways (better than mine) to do it in a one-liner.
hope this helps,
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 03:53 PM
тАО05-25-2005 03:53 PM
Re: problem with "-"
I'm not exactly sure what you want to have happen. If thise reply does not help enough you may want to provide some sample input and describe the desired effect in detail.
Anyway, I suspect that the answer to your question is to follow the mv -f with --
That will stop further option processing:
Example:
$ cat > -x
test
$ ls -1
-x
$ mv -f -x xx
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
$
$ mv -f -- -x xx
$ ls -1
xx
btw... instead of: ls -a *.res |awk '{print $9}'
Why not just use: ls -a1 *.res
hth,
Hein.
- Tags:
- --
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 04:11 PM
тАО05-25-2005 04:11 PM
Re: problem with "-"
I have a filename named as:
-_fpar__47713-5__4228_1116921571865.res
-_fpar__47714-8__4506_1116856891860.res
-_fpar__LOT ID__-_1116975671850.res
The problem occurs when i tried to move the files above using the script i've made.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 11:06 PM
тАО05-25-2005 11:06 PM
Re: problem with "-"
The 'mv' command is seeing the first '-' of the filename as another command option. The '--' says "no further options".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2005 11:57 PM
тАО05-25-2005 11:57 PM
Re: problem with "-"
$Exepath/mv -f ./$FILE $temp
You can make your script as,
cd
for file in `find . -name "-*.res"`
do
$Exepath/mv -f $FILE $temp
fi
done
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2005 12:53 AM
тАО05-26-2005 12:53 AM
SolutionWhat shell are you using?
Did you try the -- as I suggested?
You need it in more places than just the mv.
Trying a quick reproducer, I (of course) even needed it on the 'touch' to create test files.
And then there is the space in one of the names to make the touch create tow files.
In ended up using perl to quickly create your files from your list:
$ perl -ne 'chop; open(X,">$_")' < x
(x was a file with your 3 sample filenames pasted into it)
Someone must really not like you to pick such ugly file names! Fix the source ?!
I also needed -- on the ls command, otherwise you get putput like:
ls: illegal option -- _
ls: illegal option -- _
ls: illegal option -- _
ls: illegal option -- 4
ls: illegal option -- 7
ls: illegal option -- 7
ls: illegal option -- 3
:
Seeing the file names you are challenged with does help us help you, but it is still not clear to me which files need to be moved where. And I see no "|" that is used for awk parsing, nor ^Product in the examples.
Given the ugly names with spaces, READ will have problems, so I would suggest to check out perl for the whole job. For example, here is a one-liner to move all the files startign with "-" in the name to a sub directory "tmp".
perl -e ' while (<*.res>) { rename $_, "tmp/$_" if /^-/ }'
It would be trivial to expend that to parse for |, or Product, or remove the "-".
Good luck!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-26-2005 05:50 AM
тАО05-26-2005 05:50 AM
Re: problem with "-"
the problem is, that "mv" is not able to detect the end of your parameters.
So either use ./ as a prefix to your file, if you can ensure you are in a local directory or check the "mv" manpage, if your "mv"-version supports the "--" option to show the end of Parameters to "mv".
Use it like this
mv -f -- ............
Hope this helps
Volker