Get line number with bash in R

using

system(paste("wc -l file_1.txt")) 

in R to get the line number of the file Output

1601 file_1.txt

My problem is that if I type system (paste ("wc -l file_1.txt")) β†’ kt and then

 kt [1] 0 

I would have to say

 system(paste("wc -l file_1.txt"))->kt kt[1]==1600 

or not .. but I can’t access the elements from the system commadn or printout ... how can I do this to somehow check if the file has 1600 lines without reading it first in R ...

+6
source share
1 answer

system returns the return value of your command by default, you need to use the intern argument:

 system(paste("wc -l banner.p"), intern=T)->kt 

kt will be some string like

 <lines> <filename> 

And then you can parse the string.

+4
source

Source: https://habr.com/ru/post/988170/


All Articles