I must use C-shell. I have a 40+ list of ip and hostname in text file.

and so on..

i want to set the ip and hostname as list of array. The first array is hostname ; sat1 sat2 sat3 and second array the ip address.For example:

array1 = (sat1 sat2 sat3) array2 = (

how to make the ip and hostname from the .txt file to list of array?

  • 3
    What are you actually trying to solve here? This sounds like the XY problem. For instance, if what you want is to be able to look up the data later in a script, you could just use awk. – Wildcard Nov 12 '15 at 5:15
  • one of the disadvantages of using csh for scripting (apart from the fact that it is buggy) is that hardly anyone else uses it for scripting (and almost no experts do).....so finding documentation, examples, tutorials etc or getting high-quality help with it is difficult. As has been mentioned, awk is a far better language for this task. perl would be as good. bash or ksh would be better than csh. – cas Nov 12 '15 at 6:07
  • name=( $(awk '{print $2}' ./yosh.txt) ) ...whats wrong with this code? – exid Nov 12 '15 at 7:35

while IFS= read -r line; do
#echo ${array1[i]} ${array2[i]}
i=$((i + 1))
done <$1

for every line it reads it will slice it and store it into the eq. array slot. I didnt add the echos for arrayX[i] but you can test that. I hope this works for you.

  • I just saw you wanted this in csh, apologies! – onlyf Nov 12 '15 at 6:03
  • do you have idea in csh? – exid Nov 12 '15 at 6:06
  • This script assumes fixed hostname (and thus line) length. What if a line is "hellothereIamLoopback" ? – dave_alcarin Nov 12 '15 at 8:18
  • the script assume the hostname have fixed leghth – exid Nov 12 '15 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.