In bash, how to do it?
For eg i have a text file named FILE1 having 4 paths in it seperated by new line:
abc/def/zzz.txt
ghi.jkl/zzz.txt
mno.pqr/zzz.txt
stu.wvx/zzz.txt
I want to create another file named FILE2 from FILE1, which only includes:
abc/def/
ghi/jkl/
mno/pqr/
stu/wvx/
How to do this?
#!/bin/bash
for line in $(cat FILE1)
do
echo "${line%/*}/" >> FILE2
done
or
#!/bin/bash
while read -r line
do
echo "${line%/*}/" >> FILE2
done < FILE1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.