- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Awk in Shell
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
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
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
тАО03-22-2007 04:57 PM
тАО03-22-2007 04:57 PM
Awk in Shell
The following is a part of my shell script.
----------------------------------------------
echo "$value $value2"|awk '
{
if ($1 <= $2)
system($command);
else
print 0;
}'
----------------------------------------------
where I have assigned some command to $command.
While running the script I am getting the error like
----------------------------------------------
Value1 is: 903824
Value2 is: 2456910.90
903824 2456910.90
awk: Field $() is not correct.
The input line number is 1.
The source line number is 4.
----------------------------------------------
But if i change the if condition to $1>=$2,
I am getting the output like,
------------------------
Value1 is: 903837
Value2 is: 2456972.10
903837 2456972.10
0
--------------------------
Is there any other way to compare 2 floating values other than the above.
Could you please clarify me in the above and to rectify my errors
Thanks,
Arun
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 05:22 PM
тАО03-22-2007 05:22 PM
Re: Awk in Shell
Since your awk script is in '', $variables aren't expanded and they are treated as awk fields.
You will have to change the script to:
echo "$value $value2"|awk -v command="$command" '
{...
system(command);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 08:03 PM
тАО03-22-2007 08:03 PM
Re: Awk in Shell
another possibilities to give awk the content of a shell variable:
1)
echo "$value $value2"|awk '
{
if ($1 <= $2)
system("'"$command"'");
else
print 0;
}'
2)
export command
echo "$value $value2"|awk '
{
if ($1 <= $2)
system(ENVIRON["command"]);
else
print 0;
}'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-24-2007 01:14 AM
тАО03-24-2007 01:14 AM
Re: Awk in Shell
I have no HPUX system up right now to test, so I tried on Windoze..
- Are you sure ydeou want those quotes around the values? On Windows they ended up in $1 and $2. To test replace the system call with 'print "1:", $1, "2:", $2'.
- Clean up the if-then-else.
Use parantheses:
if ($1 <= $2) {
system($command);
} else {
print 0;
}
- As replied... the $command substitution will not work. You'll need to feed it through ENVIRON or a -v, or as still more text to that echo:
echo "$v1 $v2 $command" | ....
...system ("$3 $4 $5...)"...
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2007 03:15 AM
тАО04-24-2007 03:15 AM
Re: Awk in Shell
Thanks,
Arun