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...
In Bash, $LINENO contains the line number where the script currently executing. If you need to know the line number where the function was called, try $BASH_LINENO . Note that this variable is an array. See here for details of Bash variables.
Printing Newline in Bash The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way. However, it's also possible to denote newlines using the “$” sign.
Method 1: Using read command and while loop We can use the read command to read the contents of a file line by line. We use the -r argument to the read command to avoid any backslash-escaped characters.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With