HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: storing columns in different variables
Operating System - HP-UX
1834930
Members
2811
Online
110071
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
02-20-2004 04:43 AM
02-20-2004 04:43 AM
Hi,
Please find attached a file which has 2 columns. I need to store the column values in 2 different variables and use them in a SHELL script. I have an excutable which takes the coulmn values as parameters.
Thanks,
Andy
Please find attached a file which has 2 columns. I need to store the column values in 2 different variables and use them in a SHELL script. I have an excutable which takes the coulmn values as parameters.
Thanks,
Andy
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2004 04:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2004 08:50 AM
02-20-2004 08:50 AM
Re: storing columns in different variables
Clay's script is, as he said, trivially simple. Its is limited to parsing the table from the beginning to the end. But what if you wanted to start at the end, and work up to the beginning? Here's a (probably needlessly) complex way to do this:
#!/usr/bin/ksh
LENGTH=`wc -l $FILE|awk '{ print $1 }'`
while test "$LENGTH" -ge "1"
do
LINE=`head -"$LENGTH" $FILE|tail -1`
A=`echo $LINE|awk '{ print $1 }'`
B=`echo $LINE|awk '{ print $2 }'`
(( LENGTH = "$LENGTH" - "1" ))
done
Another advantage (if there is one) is that not every version of Unix has the read command. But every one that I've ever seen has head, tail, and awk. Some versions (System V derivations, like old SCO) don't have wc either. If so, use
LENGTH=`pr -n -t $FILE|tail -1|awk '{ print $1 }'`
instead of the previous LENGTH statement. This uses up a lot more clock cycles than Clays script, but is portable across every version of Unix that I've ever seen. Its handy for log files.
Chris
#!/usr/bin/ksh
LENGTH=`wc -l $FILE|awk '{ print $1 }'`
while test "$LENGTH" -ge "1"
do
LINE=`head -"$LENGTH" $FILE|tail -1`
A=`echo $LINE|awk '{ print $1 }'`
B=`echo $LINE|awk '{ print $2 }'`
(( LENGTH = "$LENGTH" - "1" ))
done
Another advantage (if there is one) is that not every version of Unix has the read command. But every one that I've ever seen has head, tail, and awk. Some versions (System V derivations, like old SCO) don't have wc either. If so, use
LENGTH=`pr -n -t $FILE|tail -1|awk '{ print $1 }'`
instead of the previous LENGTH statement. This uses up a lot more clock cycles than Clays script, but is portable across every version of Unix that I've ever seen. Its handy for log files.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2004 07:49 PM
02-20-2004 07:49 PM
Re: storing columns in different variables
Hi,
this will probably also work:
# A=$(cut -f1 infile)
# B=$(cut -f2 infile1)
regards,
John K.
this will probably also work:
# A=$(cut -f1 infile)
# B=$(cut -f2 infile1)
regards,
John K.
it would be nice if you always got a second chance
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP