If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > [sed script] extract environment variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-05-04, 07:55
AnneSoph AnneSoph is offline
Registered User
 
Join Date: Jan 2004
Posts: 2
[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!
Reply With Quote
  #2 (permalink)  
Old 01-05-04, 12:37
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On