Use bash to read a file and then execute a command from the words extracted

后端 未结 3 1263
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 08:12

FILE:

hello
world

I would like to use a scripting language (BASH) to execute a command that reads each WORD i

相关标签:
3条回答
  • 2020-12-24 08:43

    You can use the "for" loop to do this. something like..

    for WORD in `cat FILE`
    do
       echo $WORD
       command $WORD > $WORD
    done
    
    0 讨论(0)
  • 2020-12-24 08:51
    IFS=$'\n';for line in `cat FILEPATH`; do command ${line} > ${line}; done
    
    0 讨论(0)
  • 2020-12-24 08:54

    normally i would ask what have you tried.

    while read -r line 
    do 
       command ${line} > ${line}.txt
    done< "file"
    
    0 讨论(0)
提交回复
热议问题