Say I have a file which contains several hundred lines of content for example:
content.txt
contains lines in the format
element1\n
element2\n
element3\n
...
Using the command line in linux is it possible to run a linux program with each element in the file minus it's \\n
as an argument
for example:
$ linuxCommand element1
$ linuxCommand element2
$ linuxCommand element3
$ linuxCommand ...
You can do it like this:
cat content.txt | while read line; do linuxCommand "$line"; done
With the bash
shell, this is also possible:
for line in $(<content.txt); do linuxCommand "$line"; done
Yes, use xargs
:
xargs -l linuxCommand <content.txt
The -l
command line option limits the number of arguments for each invocation of linuxCommand
to one.
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.