1829570 Members
1520 Online
109992 Solutions
New Discussion

C shell error

 
Dave Walley
Frequent Advisor

C shell error

Hi.

I am trying to extract from a file certain fields using a foreach loop as follows

foreach gen (`cat davey | cut -d: -f1-2 ` )

and when I run it I get the message

cat davey
cut -d: -f1-2
Too many words from ``.

Can anyone tell me what I am doing wrong.

Dave
why do i do this to myself
2 REPLIES 2
John Palmer
Honored Contributor

Re: C shell error

I would guess that the cat | cut commands are generating more values then the shell is able to hold.

I'm no C shell expert but you could get round this in the Posix shell by reading the variable in a loop:-

cut -d: -f1-2 davey | {
while read gen
do

done
}

P V Patel
Advisor

Re: C shell error

HI,
`cat davey | cut -d: -f1-2`
this will return first tow fields (words).
for example davey contain following line
aaaa : bbbb:cccc:dddd
then corresponding selection is
aaaa : bbbb
If your aim is to extract only one word, you have to modify command appropriately.
P V Patel
Punjabhai