Looping over input fields as array

前端 未结 4 1156
夕颜
夕颜 2021-01-03 19:04

Is it possible to do something like this:

$ cat foo.txt
1 2 3 4
foo bar baz
hello world
$ awk \'{ for(i in $){ print $[i]; } }\' foo.txt
1
2
3
4
foo
bar
baz
         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-03 19:19

    No need for awk, sed or perl. You can easily do this directly in the shell:

    for i in $(cat foo.txt); do echo "$i"; done
    

提交回复
热议问题