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

前端 未结 9 1531
梦谈多话
梦谈多话 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:45

    You can also use AWK which can give you more flexibility to handle the file

    awk '{ print "chmod 755 "$0"" | "/bin/sh"}' file.txt
    

    if your file has a field separator like:

    field1,field2,field3

    To get only the first field you do

    awk -F, '{ print "chmod 755 "$1"" | "/bin/sh"}' file.txt
    

    You can check more details on GNU Documentation https://www.gnu.org/software/gawk/manual/html_node/Very-Simple.html#Very-Simple

提交回复
热议问题