Home How to exclude rows from a text file for loop
Reply: 0

How to exclude rows from a text file for loop

user9394 Published in September 20, 2018, 12:44 pm

I have a textfile (file1.txt) with multiple lines of data. This textfile I'm using to copy data from a directory A to another B. My script looks if an expression is included in a filename of a file stored in A. In the directory A I grep another textfile (file2.txt) to get information (rows like [bla][0-9][0-9][bla][0-9][0-9]) that I want to exclude in my script.

set x = `grep '[bla][0-9][0-9][bla][0-9][0-9]' file1.txt`

foreach i ( $x )
    cp A/*$i* B/.

For example rows in file1.txt:


and grep result from file2.txt that has to be excluded for the loop


My script should finally only use the following lines


How can I do this?

share|improve this question
  • Where did you get that syntax from? – Tom Fenech Nov 11 '14 at 14:01
  • That would appear to be csh syntax (or something close to it). – Etan Reisner Nov 11 '14 at 14:03
  • Would it be a good idea to change the tags? Stefan, can you clarify which shell you are working in? – Tom Fenech Nov 11 '14 at 14:05
  • It is a C-shell script – Stefan Nov 11 '14 at 14:08
  • Make the first line be /bin/csh -vx to see what is being executed and when. This will show you what values are being used for each variable as each line of code is executed. Good luck. – shellter Nov 11 '14 at 14:16

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306361 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO