Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Extracting the 4th word of the first line in a file - is there a more elegant solution?



On May 18,  2:30pm, Peter Stephenson wrote:
}
} You can do it without an auxiliary process, but with a local variable,
} which is probably more efficient and the best compromise:
} 
}   read -A line <$1
}   field=$line[4]

If you're already using a local throwaway,

    read x x x field x <$1

Or you can use the omnipresent local argv so you needn't declare it:

    (){ read -A argv; field=$4 } < $1

} You might want "read -qe" if the file contains backslashes.

I believe -q is a typo for -r there.



Messages sorted by: Reverse Date, Date, Thread, Author