Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    2

    Unanswered: [sed script] extract environment variables

    My Unix file from which I want to extract environment variables looks like:
    var1=content1 var2=content2 var3=content3
    var4=content4
    var5=content5 var6=content6

    I would like to convert this file to the following form to be able to convert var1... into environemnt variables:
    var1=content1
    var2=content2
    var3=content3
    var4=content4
    var5=content5
    var6=content6

    Is it possible with sed? Thanks a lot for your help!

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    The following are a couple of examples of how to replace spaces with newlines:

    sed 's/ /\
    /g' yourFile

    awk '{for (i=1; i<=NF;i++){print $i}}' yourFile

    What would you do though if your file contained the following sort of data?

    nastyFile
    -----------
    var1="value for var1" var2="value for var2"
    var3="value for var3"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •