在倒数第二个管道之后删除管道分隔文件中的所有内容

时间:2016-12-14 18:46:00

标签: bash shell unix ksh

如何在倒数第二个管道之后删除管道分隔文件中的所有内容?喜欢这条线

David|3456|ACCOUNT|MALFUNCTION|CANON|456

结果应该是

David|3456|ACCOUNT|MALFUNCTION

4 个答案:

答案 0 :(得分:2)

在每行末尾替换mat <- matrix(unlist(lstVec), ncol = 2, byrow = TRUE)

|(string without pipe)|(string without pipe)

答案 1 :(得分:1)

使用async Task methodA() { while (something) { Task b = methodB(); // do stuff await b; } } ,例如

awk

(或)使用awk -F'|' 'BEGIN{OFS="|"}{NF=NF-2; print}' inputfile David|3456|ACCOUNT|MALFUNCTION 如果您知道总数的列数,即{e cut

6 -> 4

答案 2 :(得分:0)

我将使用的命令是

def estimate_sigma(hist):
    bin_edges = np.arange(len(hist))
    bin_centres = bin_edges + 0.5

    # Define model function to be used to fit to the data above:
    def gauss(x, *gparams):
        g_count = len(gparams)/3
        def gauss_impl(x, A, mu, sigma):
            return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))
        res = np.zeros(len(x))
        for gi in range(g_count):
            res += gauss_impl(x, gparams[gi*3], gparams[gi*3+1], gparams[gi*3+2])
        return res

    # p0 is the initial guess for the fitting coefficients (A, mu and sigma above)
    curves_count = 4
    p0 = np.tile([1., 0., 1.], curves_count)

    coeff, var_matrix = curve_fit(gauss, bin_centres, hist, p0=p0)

    # Get the fitted curve
    hist_fit = gauss(bin_centres, *coeff)

    plt.plot(bin_centres, hist, label='Test data')
    plt.plot(bin_centres, hist_fit, label='Fitted data')

    # Finally, lets get the fitting parameters, i.e. the mean and standard deviation:
    print coeff

    plt.show()

答案 3 :(得分:0)

纯粹的Bash解决方案:

while IFS= read -r line || [[ -n $line ]] ; do
    printf '%s\n' "${line%|*|*}"
done <inputfile

有关while循环如何工作的详细信息,请参阅Reading input files by line using read command in shell scripting skips last line(特别是answer by Jahid)。

有关${line%|*|*}的信息,请参阅pattern matching in Bash