我有一个输入文件,其格式如下 -
FIT-I6-INL-PCG,['3.MYFIT-LTR-DYN'],2015-03-11 04:00:00+0000,
这里我复制了三个不同的字段,(逗号)我想删除每个有空字段的行。在上面的情况下,第一行有一个空字段SO o / p应该是
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>../../../../../..</classpathPrefix>
<classpathLayoutType>repository</classpathLayoutType>
<mainClass>com.MainClass</mainClass>
</manifest>
<manifestEntries>
<Implementation-Build>1</Implementation-Build>
<Implementation-Version>1.2</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
答案 0 :(得分:3)
您可以使用此sed:
sed -i.bak -E '/^,|,,/d' file
cat file
FIT-I6-INL-PCG,['3.MYFIT-LTR-DYN'],2015-03-11 04:00:00+0000,
如果逗号是第一个字符或者有两个逗号,则 /^,|,,/d
将删除一行。
答案 1 :(得分:2)
使用grep:
grep -v '^,\|,,' file
使用sed:
sed '/^,\|,,/d' file
如果您想就地更改文件,请:
sed -i.bak '/^,\|,,/d' file
# Or with grep:
# echo "$(grep -v '^,\|,,' file)" >file