How to add text at the end of each line in unix

前端 未结 4 1452
野性不改
野性不改 2020-12-02 20:31

I am doing certain text processing operations and finally able to get a file something like this

india
sudan
japan
france

now I want to add

4条回答
  •  一生所求
    2020-12-02 20:58

    You can also use xargs with echo for this:

    < file xargs -d "\n" -rI % echo '% | COUNTRY'
    

    This will make xargs take each line of file and pass it one at a time† to the specified echo command, replacing the % (or whatever character you choose) with the input line.

    † By default xargs will pass multiple lines of input to a single command, appending them all to its argument list. But specifying -I % makes xargs put the input at the specified place in the command, and only put one line there at a time, running echo as many times as required.

提交回复
热议问题