我有这个txt文件:
c("\\f0\\fs24 \\cf0 <message messageId=\"12450\" replyToMessageId=\"0\" receivedAt=\"2023-06-12T08:42:31Z\" text=\"> GBPJPY SELL 175.41

SL: 175.955
TP: 174.382
--Trade by Grace\" />\\",
"", " <message messageId=\"12448\" replyToMessageId=\"12442\" receivedAt=\"2023-06-12T02:38:51Z\" text=\"> SET SL TO 1.32979\" />\\",
" <message messageId=\"12447\" replyToMessageId=\"12442\" receivedAt=\"2023-06-12T02:38:51Z\" text=\"> USDCAD CLOSE HALF 33 PIPS PROFIT \" />\\",
" <message messageId=\"12446\" replyToMessageId=\"12430\" receivedAt=\"2023-06-12T00:42:27Z\" text=\"> EURAUD RUNNING 105+ PIPS PROFIT 
SMALL LOT HOLDER CAN FULL CLOSE WITH PROFIT \" />\\",
" <message messageId=\"12442\" replyToMessageId=\"0\" receivedAt=\"2023-06-09T14:42:21Z\" text=\"> USDCAD BUY 1.3328

SL: 1.31655
TP: 1.34473
--Trade by Jason\" />\\",
" <message messageId=\"12441\" replyToMessageId=\"12430\" receivedAt=\"2023-06-09T14:25:46Z\" text=\"> EURAUD CLOSE PARTIAL 69 PIPS PROFIT MOVE SL TO ENTRY\" />\\",
" <message messageId=\"12440\" replyToMessageId=\"12436\" receivedAt=\"2023-06-09T12:33:37Z\" text=\"> SET SL TO 175.401\" />\\",
" <message messageId=\"12439\" replyToMessageId=\"12436\" receivedAt=\"2023-06-09T12:33:36Z\" text=\"> GBPJPY CLOSE HALF 34 PIPS PROFIT \" />\\",
" <message messageId=\"12438\" replyToMessageId=\"12430\" receivedAt=\"2023-06-09T12:32:57Z\" text=\"> SET SL TO 1.60599\" />\\"
)
字符串
如何删除前5行而不再次阅读文件?
2条答案
按热度按时间ymdaylpp1#
你不能在没有阅读文件的情况下从文件中删除行。但是,你可以用减去前5行的内容覆盖文件。下面是你如何在Python中做到这一点:
字符串
在R中,你可以使用readLines函数将文件读入一个vector,然后使用writeLines函数将修改后的vector写回文件。下面是你如何做到这一点:
型
33qvvth12#
我们可以简单地做:
字符串
这种方法将删除第1-5行。如果数据已经存储在变量中,则不需要重新加载它。