list and export strings in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting list and export strings in a file
# 1  
Old 09-19-2008
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  
Old 09-19-2008
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  
Old 09-19-2008
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  
Old 09-19-2008
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.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

3. Shell Programming and Scripting

Searching for a list of strings in a file with Python

Hi guys, I'm trying to search for several strings, which I have in a .txt file line by line, on another file. So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt. So far, I've been able to do this, to search for individual strings: ... (1 Reply)
Discussion started by: starriol
1 Replies

4. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

5. Shell Programming and Scripting

Extract two strings from a file and create a new file with these strings

I have the following lines in a log file. It would be great if some one can help me to create a new file with the just entries in the below format. 66.150.161.195 HPSAC=Z05 66.150.161.196 HPSAC=A05 That is just extract the IP address and the string DPSAC=its value 66.150.161.195 -... (1 Reply)
Discussion started by: Tuxidow
1 Replies

6. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

7. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

8. Shell Programming and Scripting

find string(s) in text file and nearby data, export to list help

Hi, So I'm kinda new to shell scripts and the like. I've picked up quite a bit of use from browsing the forums here but ran into a new one that I can't seem to find an answer for. I'm looking to parse/find a string AND the next 15 or so charachters that follow the string within a text file... (1 Reply)
Discussion started by: kar23me
1 Replies

9. UNIX for Dummies Questions & Answers

Delete strings in file1 based on the list of strings in file2

Hello guys, should be a very easy questn for you: I need to delete strings in file1 based on the list of strings in file2. like file2: word1_word2_ word3_word5_ word3_word4_ word6_word7_ file1: word1_word2_otherwords..,word3_word5_others... (7 Replies)
Discussion started by: roussine
7 Replies

10. UNIX for Advanced & Expert Users

NFS export need to be able to write to directory but not list

My issue is I want an NFS share where I can write to the directory, but not list any of the files in there. (doesn't matter if someone knows the name can open the file). Have an NFS export for example: drwxrwxrw- 2 cranes staff 256 18 May 12:48 cranes The export will only... (1 Reply)
Discussion started by: Cranie
1 Replies
Login or Register to Ask a Question