[solved] how to get specific env variable values into a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [solved] how to get specific env variable values into a file
# 1  
Old 08-12-2011
[solved] how to get specific env variable values into a file

greetings!

how do i get an env variable that looks like this when echoed:

Quote:
t70cfd139 8 t70cfd144 8 t70cra101 8 t70hilb132 4 ttcaahi011 8
into a file that looks like this:

Quote:
t70cfd139
t70cfd144
t70cra101
t70hilb132
ttcaahi011
keeping in mind that the two constants are the fields from the env variable will always be in odd positions of the string that need to go into the file AND they will always start with a "t". however it could be as few as 1 or as many as 20.

thanx in advance!
# 2  
Old 08-12-2011
If you are on Linux, this should work, on other UNIX flavor's you may have to tweak grep. let me know how it goes and what flavor of NIX did you try.

/
Code:
opt$ echo "t70cfd139 8 t70cfd144 8 t70cra101 8 t70hilb132 4 ttcaahi011 8"|tr -s " " "\n"|grep -v ^[0-9]

here is the output from above command.
t70cfd139
t70cfd144
t70cra101
t70hilb132
ttcaahi011
This User Gave Thanks to dude2cool For This Post:
# 3  
Old 08-12-2011
worked like a charm on rhel5.

so much cleaner than what i had done. thanx so much.
# 4  
Old 08-12-2011
Quote:
Originally Posted by crimso
worked like a charm on rhel5.

so much cleaner than what i had done. thanx so much.
No problem Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get specific values from a file, help

Dear all, I have a specific problem that i cannot solve and I hope someone here can help me. :) I have two text files with one column of values. Example: File1: 67 94 95 . . File2 0.1 0.003 0.5 . . (3 Replies)
Discussion started by: Higgo
3 Replies

2. Shell Programming and Scripting

[Solved] How to print specific text from a file?

Hi All, I have the below text file from which I have to cut particular section starting from PTR_Security_Rpeorting.cpf to PTR_Security_Reporting_Env93_export. Report Model............: "D:\Cognos_Publishing\tmp.a2R94KLQec"\PTR_Security_Reporting.cpf Report Output Script....:... (4 Replies)
Discussion started by: Vikram_Tanwar12
4 Replies

3. Shell Programming and Scripting

[SOLVED] UNIX FOR loop to read a variable with multiple values

Hi, I have a variable which stores file names as a result of find command. I need to delete all these files one by one, i.e. by a loop. Can anyone tell me how can it be done? The variable f2d has the file names like these abc.txt bcd.txt fff.txt gef.txt Now I have used a loop as... (12 Replies)
Discussion started by: jhilmil
12 Replies

4. UNIX for Dummies Questions & Answers

[solved] Where & what bash env file, Mac OS?

Hi! I wanted to simplify my bash prompt, so I edited my etc/bashrc file. I thought this was the file that would override any other env files. When I opened it, I saw that the way it was setup was not what my prompt looked like, although I forget exactly what was there. But i edited it the way I... (1 Reply)
Discussion started by: sudon't
1 Replies

5. Shell Programming and Scripting

Insert value of env variable in xml file

Hello, I have the following variables set in my env echo $MY_XSD_FILE /home/jak/sample.xsd echo $MY_INTERVAL_VALUE 4 I want to insert them between the xml tags in my xml file cat sample.xml ::::::::::::::: ::::::::::::::: <property name="FILE"></property> :::::::::::::::::::::::... (2 Replies)
Discussion started by: jakSun8
2 Replies

6. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

7. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

8. Shell Programming and Scripting

UNIX Env values in HTML file

Hi, I am sending 'mailx' one file.html from unix, and i want to put the field values from the unix environment.. like. <p><input type="text" name="name" value="Your name" /></p> in thin i want to put value "Your name" as let's say $HOME, can this be possible? If yes..can anyone please... (1 Reply)
Discussion started by: jaiankur
1 Replies

9. Shell Programming and Scripting

Add env variable in a file

Hi, I have a small requirement set -x `grep IMPACT_HOME=/opt/impact /opt/NETCOOLINST/r.txt | cut -d'=' -f2` if ; then sed 's#IMPACT_HOME=*#d' /opt/NETCOOLINST/r.txt echo "IMPACT_HOME=" >> /opt/NETCOOLINST/r.txt sed 's#IMPACT_HOME=*#IMPACT_HOME=/opt/impact#g' /opt/NETCOOLINST/r.txt... (2 Replies)
Discussion started by: dbashyam
2 Replies

10. Shell Programming and Scripting

ksh help assigning specific values to variable in script

Hi - Help needed. I have an input file that looks something like this, but with a lot more entries: A Customer1 B 4500 C 8000 A Customer2 B 6422 C 8922 I need to be able to print details for each customer on one line per customer. ie. if I could print these to a file and then cat... (3 Replies)
Discussion started by: frustrated1
3 Replies
Login or Register to Ask a Question