Can you tell me how to get the line count in a script?
PID_COUNT = 'cat /david/file1/test.sh | wc -l '
is not working, shows an error "illegal -l".
Can you tell me how to get the line count in a script?
PID_COUNT = 'cat /david/file1/test.sh | wc -l '
is not working, shows an error "illegal -l".
If you want to count the number of lines in /david/file1/test.sh
use
wc -l </david/file1/test.sh
If you want to count the number of lines that /david/file1/test.sh
produces when run:
/david/file1/test.sh | wc -l
If you want to store that in a variable:
line_count=$( wc -l </david/file1/test.sh )
or
line_count=$( /david/file1/test.sh | wc -l )
depending on whether you want to count the number of lines in the file or the number of lines in the output of the script.
There are two things wrong with your command PID_COUNT = 'cat /david/file1/test.sh | wc -l'
=
.PID_COUNT
will be a string, not to output of the command. This is due to the single quotes. To capture the output of a command, use $( ... )
as above.In either case, the error is most likely "PID_COUNT: command not found" rather than "illegal -l".
wc -l
works here. Which Linux distro or UNIX system is this? Do you usewc
fromcoreutils
? Do you use a dash (-
) and the letter l (l
)? – Alexander Feb 16 '17 at 10:02