heinheo
heinheo

Reputation: 565

get line number with bash in R

using

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

in R to obtain the line number of a file The output is

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 need to be able to say whether

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

or not..but I cant access the elements from the system commadn or the printout...how can i do that to somehow check whether the file has 1600 lines without reading it into R first...

Upvotes: 7

Views: 89

Answers (1)

zw324
zw324

Reputation: 27180

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

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

kt would then be some string like

<lines> <filename>

And then you could parse the string.

Upvotes: 5

Related Questions