0

Lets say I have a directory that has the following files:

thing_one
thing_two
thing_three

I want to get an array of the second field if each file name is split on the underscore in csh. I have to use csh. Ex. one two three. I get the correct printout by using the following:

Is | awk -F_ '{ print $2 }

But, I want to assign the output to a variable. I tried using:

set output = "`ls | awk -F_ '{ print $2 }'`"

But, if I echo output, I get an array with thing_one thing_two thing_three. What am I missing? It's like the awk is being skipped.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I just noticed that the backticks didn't show in the post. There are backticks inside the double quotes on the set command. – Jacob Yacovelli Aug 11 '16 at 20:56
  • I'm using a legacy system and I can't use anything else. That's why I specified I have to use csh. Switching is not an option. – Jacob Yacovelli Aug 11 '16 at 21:02
  • You are beating a dead horse here. Trust me when I say I can't use anything else. – Jacob Yacovelli Aug 11 '16 at 21:07
  • What is the `Is` command? Should that be `ls`? – Barmar Aug 11 '16 at 21:31
  • 1
    There's no such thing as a legacy system that only has csh. Bourne shell predates C shell, and I don't think there are any systems without some form of Bourne shell. You don't have to use the same shell for scripting as you do for interactive use. – Barmar Aug 11 '16 at 21:33

1 Answers1

0

In csh, double quotes turn off the meaning of special characters within them. Try without the quotes:

    set output=`ls | awk -F_ '{ print $2 }'`
kcstricks
  • 1,489
  • 3
  • 17
  • 32