我试图弄清楚如何使用sed执行以下操作:
我得到了一个IPv4地址列表,我试图让它们在显示屏上统一.所以例如:1.2.4.32会001.002.004.032.10.125.62.1会的010.125.062.001.
我正在尝试使用sed这样做,因为这就是我现在正在学习的东西.
我得到了这两个,它将取任何一位或两位数字并在前面附加零.
sed 's/\<[0-9][0-9]\>/0&/g' file
sed 's/\<[0-9]\>/00&/g' file
Run Code Online (Sandbox Code Playgroud)
但这会遇到更实际的问题,因为我的输入文件在其他非IP地址位置会有单位或双位数字.例:
host-1 1.2.3.32
Run Code Online (Sandbox Code Playgroud)
所以我需要一种方法来寻找完整的IP地址,我认为可以通过这个来实现
sed 's/\.\<[0-9]\>/00&/g'
Run Code Online (Sandbox Code Playgroud)
但是这不仅忽略了这种情况1.something.something.something,而且00由于某种原因它也会附加在第3个八位字节的末尾.
echo "10.10.88.5" | sed 's/\.\<[0-9]\>/00&/g'
10.10.8800.5
Run Code Online (Sandbox Code Playgroud)
样本文件:
Jumpstart Server jumo 10.20.5.126
Jumpstart Server acob 10.20.5.168
NW1 H17 Node cluster 10.10.161.87
NW1 H17 Node-1 10.10.161.8
NW1 H17 Node-2 10.10.161.9
ts-nw1 10.10.8.6
Run Code Online (Sandbox Code Playgroud) 我正在尝试浏览 PADI 船宿页面以获取一些船只、出发日期和价格信息。我能够从 chrome 调试控制台获取 xpath 并让 selenium 找到它。但我想通过使用相对路径让它变得更好,但我不知道该怎么做。这是我到目前为止得到的:
from selenium import webdriver
import pdb
browser = webdriver.Chrome()
browser.get('https://travel.padi.com/s/liveaboards/caribbean/')
assert 'Caribbean' in browser.title
elem2 = browser.find_elements_by_xpath('//*[@id="search-la"]/div/div[3]/div/div[2]/div[3]/div')
print(elem2)
print(len(elem2))
browser.close()
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,代码将发送至 PADI,找到每艘潜水船的所有卡片,并将其以列表的形式返还给我。这里使用的 xpath 来自最近的可用 id,但从那时起,它都是绝对路径 div/div/div 等。我想知道是否可以以某种方式将其更改为相对路径。
谢谢。
我得到了我们假设来证明这一点perl的例子sysopen和printf,但到目前为止,它只表明死亡.
#! /usr/bin/perl
$filepath = 'myhtml.html';
sysopen (HTML, $filepath, O_RDWR|O_EXCL|O_CREAT, 0755)
or die "$filepath cannot be opened.";
printf HTML "<html>\n";
Run Code Online (Sandbox Code Playgroud)
但是当我执行代码时,它就是dies.
myhtml.html cannot be opened. at file_handle.pl line 7.
Run Code Online (Sandbox Code Playgroud)
myhtml.html不存在,但应该由O_CREAT旗帜创建.不应该吗?
编辑
我编辑了代码以包含有关use strict和的建议$!.以下是新代码及其结果.
#! /usr/bin/perl
use strict;
$filepath = "myhtml.html";
sysopen (HTML, '$filepath', O_RDWR|O_EXCL|O_CREAT, 0755)
or die "$filepath cannot be opened. $!";
printf HTML "<html>\n";
Run Code Online (Sandbox Code Playgroud)
输出,由于use strict,给了我们一大堆错误:
Global symbol "$filepath" requires explicit package name at …Run Code Online (Sandbox Code Playgroud) 我正在练习一些 C++,但在分割用户输入时遇到问题。我正在使用 eclipse ide 2020-03 和 mingw32-gcc-g++-bin 9.2.0-1。下面是我的代码,
#include <iostream>
#include <string>
using namespace std;
int main() {
string orderbook_symbol[500000][8]; //orderid, ordertime, symbol, buy/sell, qty, price, exp time, strike
string user_order;
char * pch;
string done= "done trading";
while(user_order.compare(done) != 0) {
cin >> user_order;
pch = strtok(user_order," ");
}
}
Run Code Online (Sandbox Code Playgroud)
当我点击编译时,我看到这个错误:
23:22:06 **** Incremental Build of configuration Debug for project stasd ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\stasd.o" "..\\src\\stasd.cpp"
..\src\stasd.cpp: …Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌日历和表格 API 探索 python。基本上它应该在我的日历中记录某些事件,计算有多少,并将其放入我的工作表中。
我从谷歌日历 api 快速入门示例的数组中获得了一些这样的日期信息,所以我知道我可以读取数据,但我需要从每天到每周处理它。
2017-10-23 work
2017-10-24 work
Run Code Online (Sandbox Code Playgroud)
我想将它们折叠成几周。所以上面两行应该折叠成这一行:
Oct 23- Oct 29 2 #2 instances of work.
Run Code Online (Sandbox Code Playgroud)
但我不确定如何实现这一目标。