Redirect cat output to the varible

Sun microsystems Solzi-080b99ym sw solar...
January 13, 2010 at 07:00:19
Specs: Windows XP
How can redirect output of following cat
command to any variable.
Command is :-
cat diff.txt | grep -n -v 1 | cut -d ":" -f1

Thanks,
Sagar


See More: Redirect cat output to the varible

Report •

#1
January 13, 2010 at 12:15:38
Actually, there is no reason to cat a file to most unix commands.

But to answer your question, use command substitution to send the ouput of a command to a variable:

# UNTESTED
# command substitution using bourne type shells
# that is a back tic character - not a single quote
myvar=`grep -n -v 1 diff.txt | cut -d ":" -f1`

# command substitution using bash and korn type shells
myvar=$(grep -n -v 1 diff.txt | cut -d ":" -f1)


Report •
Related Solutions


Ask Question