Linux

刪除以“/”結尾的文本行

  • July 23, 2017

我正在使用 rsync 生成已更改的文件列表,然後使用該列表將文件上傳到 s3:

rsync -av somefiles/ someotherfiles/ > list.txt


while read F  ; do
       echo $F
       aws s3 cp $lcDir/$F s3://durktest/blender/$F
done <list.txt

列表中的內容範例

swresample-2.dll
swscale-4.dll
tahoe.log
ucrtbase.dll
vcomp140.dll
vcruntime140.dll
2.78/
2.78/config/
2.78/config/bookmarks.txt
2.78/config/recent-files.txt
2.78/config/userpref.blend
2.78/datafiles/
2.78/datafiles/colormanagement/
2.78/datafiles/colormanagement/config.ocio
2.78/datafiles/colormanagement/filmic/
2.78/datafiles/colormanagement/filmic/filmic_desat65cube.spi3d
2.78/datafiles/colormanagement/filmic/filmic_false_color.spi3d
2.78/datafiles/colormanagement/filmic/filmic_to_0-35_1-30.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_0-48_1-09.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_0-60_1-04.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_0-70_1-03.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_0-85_1-011.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_0.99_1-0075.spi1d
2.78/datafiles/colormanagement/filmic/filmic_to_1.20_1-00.spi1d
2.78/datafiles/colormanagement/luts/
2.78/datafiles/colormanagement/luts/aces_to_xyz.spimtx
2.78/datafiles/colormanagement/luts/adx_adx10_to_cdd.spimtx

除了使用保險絲驅動程序並直接對s3進行rsync之外,還有什麼更好的方法嗎?

有一個更好的方法來做到這一點:使用aws s3 sync

例子

aws s3 sync somefiles/ s3://durktest/blender

閱讀AWS CLI 命令參考了解更多資訊

要刪除以 結尾的行/,只需使用sed

sed '/\/$/d'  

從標準輸入複製到標準輸出,刪除以/. 或使用grep

grep -v '/$'  

可能還有很多其他的方法。

引用自:https://unix.stackexchange.com/questions/381065