Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在某些条件下添加分隔符_Linux_Bash_Shell - Fatal编程技术网

Linux 在某些条件下添加分隔符

Linux 在某些条件下添加分隔符,linux,bash,shell,Linux,Bash,Shell,我想再添加一个分隔符“;”如果只有一项,则在行的开头。比如说, a;b c d;e Output: a;b ;;c d;e 这只是给你一个提示,告诉你如何继续这个过程,逐行检查是否找到了分隔符。剩下的就留给你了: while read line do if [ $(grep -c ';' <<< "$line") -eq 0 ] then echo delimiter not found else echo d

我想再添加一个分隔符“;”如果只有一项,则在行的开头。比如说,

a;b
c
d;e

Output:
a;b
;;c
d;e

这只是给你一个提示,告诉你如何继续这个过程,逐行检查是否找到了分隔符。剩下的就留给你了:

while read line 
do 
    if [ $(grep -c ';' <<< "$line") -eq 0 ] 
    then 
       echo delimiter not found 
    else 
       echo delimiter found 
    fi 
done < your_file
读取行时
做

如果[$(grep-c';”,那么我们鼓励用户添加他们为解决自己的问题所付出的努力,所以请添加相同的努力,然后让我们知道。示例有两个分隔符。是否需要将其填充到3的宽度?