Avoiding some files inside a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Avoiding some files inside a loop
# 1  
Old 06-14-2013
Avoiding some files inside a loop

In my script I need to loop around some files like below
example files are
fa.info.abcd
fa.info.bxde
fa.info.cdas
------
Code:
  
for test_data in fa.info.*
do
 # Some text appending logic applied 
 # Copy to another directory
done

Now I need to discard some files while looping around
for example if a files of below comes inside the loop i should avoid them and go to the next file
fa.info.ctye
fa.info.aicq
fa.info.auev
------
What logic/command is used to discard some files inside the loop !!
Thank You
# 2  
Old 06-14-2013
Is this a homework assignment?
# 3  
Old 06-14-2013
Code

Code:
 
for test_data in fa.info.*
do
temp=`echo "$test_data"|grep -v 'abcd|bxde|cdas'`
#use temp variable instead of test_data
done


you got to replace 'abcd|bxde|cdas' with a logic which defines or recognize last 4 chars of your files then assign the result to another var (i used temp here). and use that variable then on.
# 4  
Old 06-14-2013
Thank You Gaurav,

When i tried like below, I'm getting 'ac' as output . But my requirement is
'ac' should be avoided .
Code:
$ echo 'ac' |grep -v 'abc|ac'
ac

Please suggest me in this. This is not Home Work. This is my requirement

Thanks
# 5  
Old 06-14-2013
Quote:
Originally Posted by smile689
When i tried like below, I'm getting 'ac' as output . But my requirement is
'ac' should be avoided .
Code:
$ echo 'ac' |grep -v 'abc|ac'
ac

Use the E flag so that grep can handle properly the pipe between the single quotes (logical 'OR') :

Code:
$ echo 'ac' |grep -vE 'abc|ac'
$

# 6  
Old 06-14-2013
Thank You for the reply

I got an error when i tried the same .
I'm using KSH
Code:
$ echo 'ac' |grep -vE 'abc|ac'
grep: illegal option -- E

Thank you
# 7  
Old 06-14-2013
Try egrep or grep -v "ab\?c"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Write a while loop inside for loop?

I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off.... I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Discussion started by: xxhieixx
3 Replies

2. Shell Programming and Scripting

Issue with copying files into dir inside for loop

Hi , I'm trying to move/copy the files inside the loop into a directory . I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file file_path="/home/etc" Last_Day=20130930 mkdir $file_path/ARC_${Last_Day} ... (3 Replies)
Discussion started by: smile689
3 Replies

3. Shell Programming and Scripting

For loop inside awk to read and print contents of files

Hello, I have a set of files Xfile0001 - Xfile0021, and the content of this files (one at a time) needs to be printed between some line (lines start with word "Generated") that I am extracting from another file called file7.txt and all the output goes into output.txt. First I tried creating a for... (5 Replies)
Discussion started by: jaldo0805
5 Replies

4. Shell Programming and Scripting

Renumber position 88-94 inside all files matching criteria inside folder

There are 4 files inside one folder matching criteria i.e. File name = ABCJmdmfbsjopXXXXXXX_mm-dd-yyyy_XXX.data Here is the Code which find the files matching criteria:- TS=`date +"%m-%d-%Y"`| for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data"` do # Matching File Processing Code.... (1 Reply)
Discussion started by: lancesunny
1 Replies

5. Shell Programming and Scripting

need help to compare 2 files inside a loop

Basically, I have a user input a colour into a variable, and then i echo that variable into a text file. Then I need to compare those 2 files which is easy using the diff command. The thing I can not get is how to do this inside of a loop until the variable matches the file. Also if the user enters... (6 Replies)
Discussion started by: cstadnyk1
6 Replies

6. Shell Programming and Scripting

Avoiding For Loop in Shell Script

I am looking to a solution to the following problem. I have a very large file that looks something like this: Each group of three numbers on each line are three probabilities that sum to one. I want to output the maximum for each group of three. So desired output would be: or... (6 Replies)
Discussion started by: hydrabane
6 Replies

7. Shell Programming and Scripting

using find but avoiding sparse files

I am no Unix administrator...I live in windows land. I wrote a script to find files of certain names and process them but was later advised to avoid checking sparse files since it would use up a lot of resources and the files I was looking for were not there. How do I avoid doing the find on... (3 Replies)
Discussion started by: shellFun
3 Replies

8. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

9. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

10. Shell Programming and Scripting

for loop, calling and editing multiple files inside

hey guys, I'm trying to call and modify multiple files inside the for loop, i can't get it to work... ------------------------ AFILE=/dir/a_file.txt BFILE=/dir/b_file.txt CFILE=/dir/c_file.txt ADESTFILE=/dir/a_dest_file.txt BDESTFILE=/dir/b_dest_file.txt... (6 Replies)
Discussion started by: DeuceLee
6 Replies
Login or Register to Ask a Question