How do you run a command for each line of a file?

前端 未结 9 1536
梦谈多话
梦谈多话 2020-11-27 10:30

For example, right now I\'m using the following to change a couple of files whose Unix paths I wrote to a file:

cat file.txt | while read in; do chmod 755 \"         


        
9条回答
  •  一生所求
    2020-11-27 10:59

    I know it's late but still

    If by any chance you run into windows saved text file with \r\n instead of \n, you might get confused by the output if your command has sth after read line as argument. So do remove \r, for example:

    cat file | tr -d '\r' | xargs -L 1 -i echo do_sth_with_{}_as_line
    

提交回复
热议问题