小编Mar*_*ark的帖子

计算C中char数组中的所有符号,而不是白色符号,所有单词和行

我得到一个任务。我必须编写一个由几个函数组成的程序来分析文本(计算单词、符号、行数,而不是白色符号等)这是我的程序:

#include <stdio.h>
#include <stdlib.h>

int allSigns(char text[])
{

    int i;
    for (i = 0; text[i] != '\0'; ++i);    
    return i;
}

int notWhiteSigns(char text[])
{
    int sum;
    for (int i = 0; text[i] != '\0'; ++i)
    {
        if (text[i] != (' ' && '\n' && '\t'))
            sum++;
    }
    return sum;
}

int words(char text[])
{
    int i;
    int sum = 0;
    for (int i = 1; text[i] != '\0'; ++i)
    {
        if (text[i] == ' ' && text[i-1] && …
Run Code Online (Sandbox Code Playgroud)

c nlp function

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

如何从 100 个文件中求和 - bash/awk?

我需要总结 100 个文件中的值。这是我输入的一部分 suma_wiazan_wodorowych_2_1.txt

2536
1928
1830
1774
1732
1673
1620
Run Code Online (Sandbox Code Playgroud)

suma_wiazan_wodorowych_2_101.txt(每个文件的名称都在变化 100,所以 1、101、201 等)

2535
1987
1895
1829
1805
1714
1657
Run Code Online (Sandbox Code Playgroud)

所以我的脚本应该将第一个文件的第一行从第二个文件的第一行添加到一百 2535+2536+..+..+2621 并针对第二个文件的第一行和第二行的第二行等等。每个文件的长度是 5000 行(所以我会有 5000 和)你有什么想法吗?

bash awk paste

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

无法加载 WSGI 应用程序“mysite.wsgi.application”;导入模块时出错

我使用 django 3.1.1 和 Python 3.8.5。我想创建简单的博客。我使用一些旧代码,其中程序员可能使用 django 1.11,所以我改变了很多东西,但现在我陷入困境

我收到错误

    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'mysite.wsgi.application' could not be loaded; Error importing module.

Run Code Online (Sandbox Code Playgroud)

当我尝试删除时

WSGI_APPLICATION = 'mysite.wsgi.application'

Run Code Online (Sandbox Code Playgroud)

我收到一个错误

ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class
Run Code Online (Sandbox Code Playgroud)

这是我的整个设置.py

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 1.8.6.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) …
Run Code Online (Sandbox Code Playgroud)

python django backend django-settings python-3.x

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

如果文件中有特定名称,则仅打印一次

我有个问题。这是我的脚本:

#!/bin/bash
file_name="eq3_luteina_horyzontalna"
file_name2="wiazanie_PO4"
tmp=$(mktemp) || exit 1  
for index in {1..405000} 
do
if ! [ -s "${file_name}_$index.ndx" ];then
    echo "0" >> ${file_name2}_POP42.txt
else
    awk '{if($2==/POP42/) print "5"; else print "0"}' ${file_name}_$index.ndx >> ${file_name2}_POP42.txt
fi
done
Run Code Online (Sandbox Code Playgroud)

问题就在这里

awk '{if($2==/POP42/) print "5"; else print "0"}' ${file_name}_$index.ndx
Run Code Online (Sandbox Code Playgroud)

我只想检查 POP42 是否在第二列的文件中并打印 5 但我有这样的数据

162 POP87
1851 POP42
Run Code Online (Sandbox Code Playgroud)

所以它会打印到我的输出文件 ${file_name2}_POP42.txt 中,类似于:

0
5
Run Code Online (Sandbox Code Playgroud)

但我想拥有

5
Run Code Online (Sandbox Code Playgroud)

另一种情况

3075 POP42
2911 POP42
Run Code Online (Sandbox Code Playgroud)

它将打印到输出

5
5
Run Code Online (Sandbox Code Playgroud)

但我只想

5
Run Code Online (Sandbox Code Playgroud)

我该如何管理我的问题?

bash awk

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

打印整行,当发现重复时

这是我输入的片段:

DGD3 SOL10
DGD53 SOL15
DGD100 SOL15
DGD92 SOL20
DGD41 SOL22
DGD62 SOL35
DGD13 SOL40
DGD13 SOL40
Run Code Online (Sandbox Code Playgroud)

我的预期输出

DGD53 SOL15
DGD100 SOL15
DGD13 SOL40
DGD13 SOL40
Run Code Online (Sandbox Code Playgroud)

在我的数据中,我有时会重复 SOL(不超过两次重复,而不是例如文件中某些 SOL 的三倍,但仅重复)。SOL 在我的第二列中($2)。因此,当我找到重复的 SOL($2)时,我需要一个打印整行(DGD 和 SOL)的程序。你可以帮帮我吗?

awk data-processing

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