x = "type='text'"
re.findall("([A-Za-z])='(.*?)')", x) # this will work like a charm and produce
# ['type', 'text']
Run Code Online (Sandbox Code Playgroud)
但是,我的问题是我想实现一个管道(交替),以便相同的正则表达式适用
x = 'type="text"' # see the quotes
Run Code Online (Sandbox Code Playgroud)
基本上,以下正则表达式应该可以工作但是findall会导致一些奇怪的事情:
([A-Za-z])=('(.*?)')|"(.*?)")
Run Code Online (Sandbox Code Playgroud)
并且我不能使用['"]而不是管道,因为它可能以不良结果结束:
value="hey there what's up?"
Run Code Online (Sandbox Code Playgroud)
现在,我如何构建适用于单引号或双引号的正则表达式?顺便说一句,请不要建议任何html或xml解析器,因为我对它们不感兴趣.
每当我执行输出多行的linux命令时,我想对输出的每一行执行一些操作.我一般都这么做
command something | while read a
do
some operation on $a;
done
Run Code Online (Sandbox Code Playgroud)
这很好用.但我的问题是,是否有一些我可以通过预定义的符号访问每一行(不知道如何调用它)///像$这样的东西?..或.. $!..或.. $ _
有可能吗?
cat to_be_removed.txt | rm -f $LINE
Run Code Online (Sandbox Code Playgroud)
在bash中有预定义的$ LINE ..或者前一个是最短的方式.即.
cat to_be_removed.txt | while read line; do rm -f $line; done;
Run Code Online (Sandbox Code Playgroud) 我试图创建一个shell脚本来回显文件的内容,我不知道在哪里找到它.
我以为它会是这样的:
$echo | ls /* | grep file.xml
Run Code Online (Sandbox Code Playgroud)
我的文件可能在某个未知的子文件夹中,所以我试图用grep搜索它的路径.
任何有关正确语法的帮助将不胜感激!
程序运行一次,它都将数据抛出到管道并以相互排斥的相同条件(在if和else中)将其取出.我没有到这里来的?这是如何运作的?我对这种编程没有经验.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
从管道中读取字符并将它们回显到stdout.
void
read_from_pipe (int file)
{
FILE *stream;
int c;
stream = fdopen (file, "r");
while ((c = fgetc (stream)) != EOF)
putchar (c);
fclose (stream);
}
Run Code Online (Sandbox Code Playgroud)
将一些随机文本写入管道.
void
write_to_pipe (int file)
{
FILE *stream;
stream = fdopen (file, "w");
fprintf (stream, "hello, world!\n");
fprintf (stream, "goodbye, world!\n");
fclose (stream);
}
int
main (void)
{
pid_t pid;
int mypipe[2];
/* Create the pipe. */
if (pipe (mypipe))
{
fprintf (stderr, "Pipe …Run Code Online (Sandbox Code Playgroud) 我不知道这是否可能,或者grep是错误的工具,还是什么,但我想要做的是:
grep -rsI "some_string" *.c
Run Code Online (Sandbox Code Playgroud)
然后将发现结果的文件列表导入第二个grep:
grep -rsI "second_string" <list of files from first grep>
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过以下方式将确切的行传输到第二个grep:
grep -rsI "some_string" *.c | grep "second_string"
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的,我不想只搜索以前点击的行,但是这些行所在的整个文件.这甚至可能吗?有任何想法吗?
I am trying to guess how much data is in pipe, and I don't want to use while(read) because it is blocking until EOF.
Is there any way to do that?
I real I want something like this:
i = pipe1.size();
pipe1.read(i);
Run Code Online (Sandbox Code Playgroud)
I say again, I don't want to use while (read) because it is blocking until EOF.
我在一本书中读到了这个例子:
cp /bin/cat proj33
echo -n x | ./proj33 - pipe33a > pipe33b &
./proj33 <pipe33b >pipe33a &
Run Code Online (Sandbox Code Playgroud)
什么符号-,>以及<是什么意思?
我想SIGNAL在.5几秒钟之后发送一个进程.
也许这不是一个好主意,但我想为一个不寻常的临时案例做这件事.
我试过跟随,但它不起作用.
(sleep .5;kill -9)| some_process
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
//Functions Prototype
void dadstuff(int [], int);
void kidstuff(int,char*, int [3][2]);
#define NUM 3;
int main(int argc, char *argv[])
{
int m = rand()%100 + 1;
int fd [3][2];
char token[] = "GO_AHEAD\n";
char readbuffer[80];
//printf("%d\n",m);
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "usage: …Run Code Online (Sandbox Code Playgroud) 我有以下Bash脚本:
cat | command1 | command2 | command3
命令永远不会改变.
出于性能原因,我想用一个小的C程序替换它,它运行命令并相应地创建和分配管道.
有没有办法在C中做到这一点?