- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Reading a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:06 AM
тАО12-12-2003 09:06 AM
I have a file where I have some properties. I want to read their value by property name like..
p1=value1
p2=value2
one time I want to read value of just p2. How do I do it?
Thanks in adv.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:30 AM
тАО12-12-2003 09:30 AM
Re: Reading a file
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:41 AM
тАО12-12-2003 09:41 AM
Re: Reading a file
I have this property file.
key1=value
key2=my value 2
key3=my value 3
In my script I want to know the values of the peroperties. I can do that with
"fgrep -i key* abc.txt"
but it returns the whole line. what I want is to retrive just the value after "key1=" in my script and assign to another variable. is there some other power utility for that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:48 AM
тАО12-12-2003 09:48 AM
Re: Reading a file
look into your other thread,
Michael
her, what I wrote:
Hi Dude70,
try this:
grep "^p2=" file
do you want to set the variable in the script or just see, what is it?
the value you get by:
string=`grep "^p2=" file`
value=`expr "${string}" : ".*=\(.*\)"`
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:49 AM
тАО12-12-2003 09:49 AM
Re: Reading a file
while read a b
do
if [ "$a" = key1 ]
then
result=$b
break
done
IFS="$SAVIFS"
Or you can do:
res=$(awk -F= '/key1/{print $2 }')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:52 AM
тАО12-12-2003 09:52 AM
Re: Reading a file
SAVIFS="$IFS"
while read a b
do
if [ "$a" = key1 ]
then
result=$b
break
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 09:57 AM
тАО12-12-2003 09:57 AM
Re: Reading a file
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 10:06 AM
тАО12-12-2003 10:06 AM
Re: Reading a file
I dont want any while loops. just read the value of key1 ie "value" and assign it to another var within script myscript.sh.
you have the file name(file.txt) that contains key1=value
some single line command will be helpful.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 10:08 AM
тАО12-12-2003 10:08 AM
Re: Reading a file
Where do you provide the file name here.
grep key2 123 |awk -F"=" '{print $2}'
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 10:13 AM
тАО12-12-2003 10:13 AM
Solutiongrep key2 your_file_name |awk -F"=" '{print $2}'
I tested with a file named "123" and pasted the command here :-))
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 10:13 AM
тАО12-12-2003 10:13 AM
Re: Reading a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 10:35 AM
тАО12-12-2003 10:35 AM
Re: Reading a file
have you tried my commands?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2003 12:35 PM
тАО12-12-2003 12:35 PM
Re: Reading a file
Thanks. It worked!