The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk:Find length of string omitting quotes jayakumarrt Shell Programming and Scripting 2 05-09-2008 12:48 AM
omitting lines from file A that are in file B gneen Shell Programming and Scripting 14 02-20-2008 02:33 AM
spaces in filenames, for do naviztirf Shell Programming and Scripting 4 10-17-2007 02:08 PM
tar contains duplicate filenames dangral UNIX for Dummies Questions & Answers 2 03-14-2007 01:18 PM
code that reads commands from the standard i/p and executes the commands Phrozen Smoke High Level Programming 4 01-21-2007 11:06 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-18-2006
milhan's Avatar
Registered User
 

Join Date: Oct 2002
Location: /home
Posts: 121
Red face Omitting some filenames for commands to process

hello all,

this topic might have been discussed but I couldn't find it with searching.

I am trying to do a for command that will dos2unix files one by one and save it under directory called backup (backup is in the same directory with other files). When I do:

Code:
for i in *
do
  dos2unix $i backup/"$i"
done
this will try to copy/dos2unix the backup directory itself too. Since it can't do it, it stops copying files. I know there is a way to specify in unix; like: everything but not something. In the above command I should be able to say

Code:
for i in * but not backup 
do
   cp files under backup
done
so that It will skip when encountered to backup directory file.

I hope I made sense...
Reply With Quote
Forum Sponsor
  #2  
Old 05-18-2006
Registered User
 

Join Date: Jul 2002
Location: HK
Posts: 20
You can try looking up the test command

you can use the if statement which also supports NOT,AND and OR.
Check you shell manuals for syntax e.g. man sh, man ksh, man csh

Here are some things you can check for with test
-r filename
True if filename exists and is readable.
-w filename
True if filename exists and is writable.
-x filename
True if filename exists and is executable.
-f filename
True if filename exists and is a regular file.
-d filename
True if filename exists and is a directory.
-h filename
True if filename exists and is a symbolic link.
With all other primitives (except -L filename),
the symbolic links are followed by default.
-s filename
True if filename exists and has a size greater
than zero.
-z s1 True if the length of string s1 is zero.
Reply With Quote
  #3  
Old 05-19-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Code:
for i in !(dos2unix)
do
  dos2unix $i backup/"$i"
done
Works in ksh and probably bash. !(x) == "everything but x".
Reply With Quote
  #4  
Old 05-19-2006
milhan's Avatar
Registered User
 

Join Date: Oct 2002
Location: /home
Posts: 121
Quote:
Originally Posted by Glenn Arndt
Code:
for i in !(dos2unix)
do
  dos2unix $i backup/"$i"
done
Works in ksh and probably bash. !(x) == "everything but x".
unfortunately, it doesn't work in bash shell, which is my favorite..

Code:
$ for i in !(backup); do dos2unix $i backup/"$i" ; done
bash: !: event not found
Thanks though, that was a good one...
Reply With Quote
  #5  
Old 05-19-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Bummer. Then I'd say to go with a test:

Code:
for i in *
do
  if [[ $i != dos2unix ]]; then
    dos2unix $i backup/"$i"
  fi
done
Reply With Quote
  #6  
Old 05-19-2006
Registered User
 

Join Date: Feb 2006
Location: California
Posts: 45
Code:
#!/bin/ksh
#
for i in *
do  
 if [ ! -d $i ] 
 then 
  dos2unix $i backup/"$i"
 fi 
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0