- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to extract a value from a inputfile in script
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
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
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
06-26-2001 12:01 PM
06-26-2001 12:01 PM
how to extract a value from a inputfile in script
I want to extract a value from a input file so
that I can use it to determine the iteration in
the c shell script file.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 12:11 PM
06-26-2001 12:11 PM
Re: how to extract a value from a inputfile in script
x=`cat file | grep
with this defined in the shell script. If this is not what your looking for, please provide and example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 12:16 PM
06-26-2001 12:16 PM
Re: how to extract a value from a inputfile in script
You can use 'awk' to read a particular file, selecting record(s) and extracting fields, as for instance:
# X=`awk '$2~/localhost/ {print $1}' /etc/hosts`
# echo $X
...which would display 127.0.0.1
You can also use the 'read' command to split a line read from a file into individual fields. Take a look at 'man read'.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 12:41 PM
06-26-2001 12:41 PM
Re: how to extract a value from a inputfile in script
something wrong. I also tried "read", it didn't work either. What I did is as following,
while (read -r xx yy)
do
printf "%s %s\n" "$yy" "$xx"
done < filein.dat
and the inputfile "filein.dat" is as following
12. 12.
11. 11.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 12:57 PM
06-26-2001 12:57 PM
Re: how to extract a value from a inputfile in script
Both the 'awk' and the 'read' will work in c-shell. Remove the parentheses surrounding the read argument to make it work:
...
while read -r xx yy
...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 01:13 PM
06-26-2001 01:13 PM
Re: how to extract a value from a inputfile in script
I did what you said. What I got is as the following,
while: Expression syntax
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 01:52 PM
06-26-2001 01:52 PM
Re: how to extract a value from a inputfile in script
My apologies! I tested the syntax but bungled specifying the C-shell!
I never use the C-shell. It's not nearly as robust as the Posix (superset of ksh) that is the HP default. The syntax I used is Posix.
For the C-shell you would do:
# set X=`awk '$2~/localhost/ {print $1}' /etc/hosts`
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 02:07 PM
06-26-2001 02:07 PM
Re: how to extract a value from a inputfile in script
guessing that your "config file" looks like:
NAME=value
you could use a line like:
result=`grep "NAME=" config-file | cut -d"=" -f2-`
that should be pretty "shell-independent" and fast
enough.
HTH,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2001 02:23 PM
06-26-2001 02:23 PM
Re: how to extract a value from a inputfile in script
If you want to read in a CSV file using the posix shell, try:
IFS=","
while read xx yy
do
echo $yy $xx
done <<.
12,13,
14,15,
.
I don't know of any equivalent for CSH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2001 08:39 AM
06-27-2001 08:39 AM
Re: how to extract a value from a inputfile in script
The follwing works, but I still don't how to read the value from the file "filein.dat"
could you tell me explicitly.
Thanks.
set X=`awk '$2~/localhost/{print$1}' /etc/hosts`
echo $X
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2001 09:57 AM
06-27-2001 09:57 AM