在bash中,怎么做?
例如,我有一个名为FILE1的文本文件,其中有4条路径,用新行分隔:
filter_backends = (CustomFilterSetBackend, filters.OrderingFilter)
custom_filters = (
........
)
ordering_fields = (............)
ordering = ('id',)
我想从FILE1创建另一个名为FILE2的文件,其中只包含:
abc/def/zzz.txt
ghi.jkl/zzz.txt
mno.pqr/zzz.txt
stu.wvx/zzz.txt
怎么做?
答案 0 :(得分:2)
答案 1 :(得分:1)
#!/bin/bash
for line in $(cat FILE1)
do
echo "${line%/*}/" >> FILE2
done
或
#!/bin/bash
while read -r line
do
echo "${line%/*}/" >> FILE2
done < FILE1