Add string to list using either AWK or SED?

6,692

Solution 1

Using sed:

$ sed 's/.*/I am & of earth;/' file.txt 
I am john of earth;
I am paul of earth;
I am rose of earth;
I am lily of earth;

Solution 2

With awk you can use print:

awk '{ print "I am", $1, "of earth;" }' list

or printf:

awk '{ printf("I am %s of earth;\n", $1); }' list
Share:
6,692

Related videos on Youtube

ayrton_senna
Author by

ayrton_senna

Updated on September 18, 2022

Comments

  • ayrton_senna
    ayrton_senna almost 2 years

    Hi I want to be able to edit the list of name like this using either AWK or SED.

    Sample input list file:

    john
    paul
    rose
    lily
    

    Desired output:

    I am john of earth;
    I am paul of earth;
    I am rose of earth;
    I am lily of earth;
    

    I want the semicolons at the end too. i don't want to use shell scripts of for loops.