小编zha*_*ing的帖子

如何在文本的某一行的末尾附加某些内容

我想在某一行的末尾添加一些东西(有一些给定的字符).例如,文本是:

Line1:  I just want to make clear of the problem
Line2:  Thanks to all who look into my problem
Line3:  How to solve the problem?
Line4:  Thanks to all.
Run Code Online (Sandbox Code Playgroud)

然后我想在最后添加"请帮助我"

Line2:  Thanks to all who look into my problem
Run Code Online (Sandbox Code Playgroud)

"Line2"是关键词.(也就是说,我必须通过关键词grep这一行来附加一些东西).

所以脚本之后的文本应该是:

Line1:  I just want to make clear of the problem
Line2:  Thanks to all who look into my problem Please help me
Line3:  How to solve the problem?
Line4:  Thanks to all.
Run Code Online (Sandbox Code Playgroud)

我知道sed可以在某些行上附加某些内容但是,如果我使用sed …

shell awk sed

13
推荐指数
2
解决办法
2万
查看次数

如何使用tshark在任何接口上的特定端口捕获包

我想在我的机器的任何接口上捕获特定端口上的包.

我知道如何使用特定接口捕获特定端口上的包.命令是

tshark -f"udp port 162"-i bond0

如果没有指定接口,TShark会搜索接口列表,如果有任何非环回接口,则选择第一个非环回接口.

但我想我的机器的所有界面上捕获包.有人可以帮我吗?

非常感谢!

packet-capture tshark

12
推荐指数
1
解决办法
2万
查看次数

shell:如何使文件的尾部在后台运行

我想在shell中运行一些任务.

  1. 将文件拖入新文件:例如: tail -f debug|tee -a test.log
  2. 同时,运行其他任务.

我的问题是:如何让命令tail -f debug|tee -a test.log在后台运行,以便我可以在shell脚本中运行其他任务?

shell tail

5
推荐指数
2
解决办法
8616
查看次数

如何让段落包含shell脚本中的关键词?

我想得到包含关键词的整段.

例如,以下是输出 "ifconfig -a"

bond0     Link encap:Ethernet  HWaddr 00:11:3F:C1:47:98  
          inet6 addr: fe80::211:3fff:fec1:4798/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:1881856 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1059020 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2618747813 (2.4 GiB)  TX bytes:182058226 (173.6 MiB)

bond0:oam Link encap:Ethernet  HWaddr 00:11:3F:C1:47:98  
          inet addr:135.2.156.97  Bcast:135.2.156.111  Mask:255.255.255.240
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1

bond0:oamA Link encap:Ethernet  HWaddr 00:11:3F:C1:47:98  
          inet addr:135.2.156.103  Bcast:135.2.156.111  Mask:255.255.255.240
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
Run Code Online (Sandbox Code Playgroud)

我想用粗体提取段落.也就是说,该段落包含"bond0:oamA" 我知道的关键词,如果我使用grep,只使用行

bond0:oamA Link encap:Ethernet …
Run Code Online (Sandbox Code Playgroud)

shell awk grep cut

3
推荐指数
1
解决办法
2328
查看次数

不是root用户,如何杀死python 2.4中的子进程

如果执行时间太长,我想杀死一个子进程。我知道我必须使用os.killos.killpg.

但是,如果我不是 root 用户,问题就会出现。例如,在我设计的GUI中,我想调用子进程,或者os.kill杀死os.killpg子进程。但我的 GUI 属于 apache。所以当涉及到命令 os.kill 时,我会得到错误:

[type: 
exceptions.OSError value: [Errno 1] Operation not permitted 
Run Code Online (Sandbox Code Playgroud)

另外,我的python版本是2.4.3。所以终止()...不能使用。

有人能给我一些想法吗?

多谢!

PS 我的代码的相关部分:

timeout=4
subp = subprocess.Popen('sudo %s'%commandtosend, shell=True,preexec_fn=os.setsid, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    while subp.poll() is None:
        time.sleep(0.1)
        now = datetime.datetime.now()
        if (now - start).seconds > timeout:
            os.kill(subp.pid, signal.SIGKILL)
            #os.killpg(subp.pid, signal.SIGKILL)
            break
Run Code Online (Sandbox Code Playgroud)

python apache user-interface subprocess

2
推荐指数
1
解决办法
5815
查看次数

在C++中打开文件时如何设置文件权限?

在C++中,我想打开一个文件并设置其权限,但我失败了.以下是我的计划:

string filename="test.cnf";
ofstream ofile;
ofile.open(filename.c_str(),O_RDONLY);
ofile.close()
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

error: invalid conversion from 'int' to 'std::_Ios_Openmode'

error:   initializing argument 2 of 'void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]'
Run Code Online (Sandbox Code Playgroud)

如何设置文件的权限,如644,700?

c++ unix file-io

2
推荐指数
1
解决办法
6200
查看次数

通过C++处理文本文件 - 从文本文件中提取某个字符串

我是C++的新学习者.我有一个文本文件,其内容如下:

Systemname    localtesthost
SystemIp      X.X.X.X
Systemowner   root
...
Run Code Online (Sandbox Code Playgroud)

现在我想提取"Systemname"的值,即"localtesthost".

我可以提取包含"Systemname localtesthost"的行,但我不知道如何提取字符串"Systemname".

以下是我的程序需要帮助:

const char* configInfoFile = "config_info";//the text file name
ifstream ifs(configInfoFile);
    string line;
    while(getline(ifs,line)) {
        if(line.length() > 0){
            int index = line.find("SystemName");
            if (index != -1)
            {

                                .
                                .

            }

        } 
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我如何提取字符串"localtesthost"吗?

非常感谢!

c++ string getline substr strtok

1
推荐指数
1
解决办法
1777
查看次数

C++:如何判断文件的路径是否以给定路径开头

我有一条路径,例如,名字

/我的/路径/测试/ mytestpath

,例如,我想判断它是否以给定路径开头

/我自己的路

c c++

1
推荐指数
1
解决办法
1014
查看次数

标签 统计

c++ ×3

shell ×3

awk ×2

apache ×1

c ×1

cut ×1

file-io ×1

getline ×1

grep ×1

packet-capture ×1

python ×1

sed ×1

string ×1

strtok ×1

subprocess ×1

substr ×1

tail ×1

tshark ×1

unix ×1

user-interface ×1