0

I am writing a c-shell script, where I am grepping two different directories in two strings. I wanted to remove the name of the directories which are the same. I only want the unique directory among the two by leaving out the duplicate ones. I am little confused about how to do this.

There are some common directories present in sta_views and pnr_views strings. I am grepped both of them using ls -l command as seen above stored them. Now what I want to do is "first we can loop over sta_view and check if that exist in the pnr_view list and if no , then put them in a separate list , if yes , then do not do anything" Hope this helps to understand you my question. Thank You!

Please let me know the approach to do it,

set pnr_views = `(ls -l pnr/rep/signoff_pnr/ | grep '^d' | awk '{print $9}'\n)`
set sta_views = `(ls -l sta/rep/ | grep '^d' | grep -v common | grep -v signoff.all.SAVEDESIGN | awk '{print $9}'\n)`

foreach i ($sta_view) 
if [$i == $pnr_view] #just want to remove the list pnr_view from sta_view
then
echo ...
else 
 

Here sta_views contains the directories that are present in pnr_views. How shall I remove the pnr_views directories from sta_views?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Please don't spam tags. If you need help with [tag:csh] don't use [tag:bash] (or [tag:sh] or [tag:python] or [tag:javascript] ... etc) – tripleee Sep 22 '21 at 07:39
  • As an aside, [don't use `ls` in scripts](https://mywiki.wooledge.org/ParsingLs) and [avoid useless `grep`](https://www.iki.fi/era/unix/award.html#grep) – tripleee Sep 22 '21 at 07:39
  • For your concideration: [Top 10 Reasons not to use C Shell](http://www.grymoire.com/unix/CshTop10.txt) and [Csh programming considered harmful](http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/) – kvantour Sep 22 '21 at 08:34

1 Answers1

0

Loop over the directories in the first directory, and simply check whether the same entry exists in the second.

foreach i ( pnr/rep/signoff_pnr/*/ )
  if ( -d sta/rep/"$i:h:t" ) then
    switch ("$i:h:t")
      case *'common'*:
      case *'signoff.all.SAVEDESIGN'*:
        breaksw
      default:
        echo sta/rep/"$i:h:t"
        breaksw
    endsw
  endif
end

The Csh variable modifier $i:h returns the directory name part of the file name in $i and the modifier :t returns the last element from that.

Csh is extremely fickle and thus these days rather unpopular; you might have better luck if you switch to a modern Bourne-compatible shell, especially if you are only just learning. See also Csh considered harmful and the other links on https://www.shlomifish.org/open-source/anti/csh/. Looping over pairs of values in bash shows how to do something similar in Bash.

tripleee
  • 175,061
  • 34
  • 275
  • 318