Omitting some filenames for commands to process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Omitting some filenames for commands to process
# 1  
Old 05-18-2006
Power 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...
# 2  
Old 05-18-2006
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.
# 3  
Old 05-19-2006
Code:
for i in !(dos2unix)
do
  dos2unix $i backup/"$i"
done

Works in ksh and probably bash. !(x) == "everything but x".
# 4  
Old 05-19-2006
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...
# 5  
Old 05-19-2006
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

# 6  
Old 05-19-2006
Code:
#!/bin/ksh
#
for i in *
do  
 if [ ! -d $i ] 
 then 
  dos2unix $i backup/"$i"
 fi 
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To run 5 commands at the same time with process from a list

I have many command is list in the variable lists,each command will run a very long time, so I want to run 5 commands at the same time with process till it complete run all the command, lists="aa bb cc dd xx gg blabla zz ......." ( a very long list) can some one point me the codes? ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

2. Shell Programming and Scripting

Omitting sections of file that contain word

I have a configuration file that contains hundreds of these chunks. Each "chunk" is the section that begins with "define service {" and ends with "}". define service { check_command check_proc!java hostgroup_name service_description ... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. UNIX for Dummies Questions & Answers

Find process by name and insert commands

I am writing a tcsh script that will open an already-running processs on a system, and give it a command. I want to have something similar to this: http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/ But I need to be able to find the process and... (5 Replies)
Discussion started by: Adorai
5 Replies

4. Shell Programming and Scripting

Omitting directory

Hello, Am trying to copy log files from one directory to other directory but the files are with date format i need it for some specific date like this find . -name 'log.2011020*' -exec cp ~/temp {} \; but its displaying the below error cp: omitting directory `/home/l828117/temp' cp:... (2 Replies)
Discussion started by: thelakbe
2 Replies

5. Shell Programming and Scripting

Multiples commands between pipes and a single process

Hi I have this script: #!/bin/ksh cmd1 | cmd 2 |cmd 3| cmd4 which it creates 4 process.... Is possible to create a single process PID1 which include all commands? Thanks Israel (2 Replies)
Discussion started by: iga3725
2 Replies

6. UNIX for Dummies Questions & Answers

Executing a sequence of commands as a single background process

I'm writing a PHP script which will take a given media file and convert it into a flash (flv) file. In addition to this, once the flv file has been generated I create two thumbnails (of different sizes) from the newly generated flv file. In order to do this I'm calling ffmpeg from the command... (4 Replies)
Discussion started by: phatphug
4 Replies

7. Shell Programming and Scripting

Omitting the last 2 alphabets in the words

Hi Guys, Bit new to Unix shell scripting so this question might seems little kiddish for you. what im trying to achieve here is : I have file which is compressed like Account_52320090605076_log.Z so in my shell script i call this file also as one of my parameters like ... (4 Replies)
Discussion started by: coolrekz
4 Replies

8. UNIX for Advanced & Expert Users

commands not working if the executed from forked process

Hi, I have an application where if it runs indivisually could able to execute commands (like system("ls")) and could able to execute tcl script. Same application if started from health monitor process (From health monitor process my application will be forked), it could not execute the... (1 Reply)
Discussion started by: chandrutiptur
1 Replies

9. Shell Programming and Scripting

find filenames like unix commands

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)
Discussion started by: deepakgang
6 Replies

10. Shell Programming and Scripting

Awk:Find length of string omitting quotes

Hi , I have a file named "sample" having the data as follows. "663005487","USD",0,1,"NR" If i give like a=`awk -F ',' '{printf length($2)}' sample` (Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5. How to do this..... (2 Replies)
Discussion started by: jayakumarrt
2 Replies
Login or Register to Ask a Question