6

I have a number in a text file like :

int_width: 5230

I want to set this number (5230) to a variable in csh. What is the correct form? (grep is working before setting)

set WIDTH = "$(grep int_width  *.txt | sed 's/[^0-9]*//g')"
muru
  • 193,181
  • 53
  • 473
  • 722
Krsztr
  • 437
  • 4
  • 7
  • 13

1 Answers1

9
  1. In order to set variable in csh you need to use set (more info)
  2. As mentioned by @muru comment - The original Bourne shell, csh or tcsh all do not support $() and require ` ` for command substitution.

Combine the above two and you'll get:

% set WIDTH=`grep int_width *.txt | sed "s,[^0-9]*,," `
% echo $WIDTH
5230
muru
  • 193,181
  • 53
  • 473
  • 722
Yaron
  • 12,828
  • 7
  • 42
  • 55