The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
List certain file in a folder and make list andrisetia UNIX for Dummies Questions & Answers 1 09-15-2008 01:21 PM
Export a file system with write permissions jredx Filesystems, Disks and Memory 7 05-27-2008 03:05 AM
Is it possible to re-export a exported NFS file system? Adams Nave Filesystems, Disks and Memory 5 03-15-2008 01:40 AM
Failed to export parameters from configuration file nir_s Shell Programming and Scripting 5 01-16-2006 03:03 AM
How to export data file from Unix whatisthis UNIX for Dummies Questions & Answers 20 03-03-2005 02:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2008
Avatar Gixxer Avatar Gixxer is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 4
list and export strings in a file

Hi all,

I have a file looks something like this:
~~~~~~~~~~~~~~~~~~~~~~~~~
aaaa
bbbbbb
ccc
dddddddd
~~~~~~~~~~~~~~~~~~~~~~~~~

I will like a script that can
echo line1
export line1 as env variable
echo line2
export line2 as env variable
etc
etc

Thanks in advance
  #2 (permalink)  
Old 09-19-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Code:
for ELE in `grep -v "^~" infile`; do
   echo "${ELE}"
   export "${ELE}"
done
Of course you should think about assigning variable names in your file.
  #3 (permalink)  
Old 09-19-2008
Avatar Gixxer Avatar Gixxer is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 4
Hi Zaxxon,

Thanks for the fast response...
It will be fine if I can set it as a variable in a file, but what I'm after is the following:

Say I have a text file named file.text that has the following entries:
aaaa
bbb
cc
d

What I want to do is to list them as a menu in format:

1) aaaa
2) bbb
3) cc
4) d

and at the same time set them as variables

sid1 = aaaa
sid2 = bbb
etc
etc

Can you please help with this, I have the following but it doesn't work like I want it to.

num = 'cat file.txt | wc -l'
for ELE in `grep -v "^~" file.txt`
do
for (( i = 0; i < num; i++))
do
echo "$i) ${ELE}"
sid $i="${ELE}"
done
done


The output from this gives:
1) aaaa
1) bbb

and doesn't set the variables correctly either.

Thanks in advance
  #4 (permalink)  
Old 09-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If your shell has select then perhaps this is sufficient.

Code:
select ELE in `cat file.txt`; do
  echo $ELE
done
(Type ctrl-D to escape from the prompt.)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0