- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: UNIX script help
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-03-2002 12:59 PM
06-03-2002 12:59 PM
UNIX script help
I am trying to write a script which will check the first field in art1 file, if it is less than 1100 it should print second field.
Here is the script:
#!/bin/sh
#
# Usage : <script_name> input_file output_file
####
# Removes previous output file
rm $2 2>/dev/null
while read LINE
do
FST_FIELD=`echo $LINE | cut -d " " -f 1`
SND_FIELD=`echo $LINE | cut -d " " -f 2`
if (( ${FST_FIELD} < 1100 ))
then
echo 'First field = '$FST_FIELD' Second Field = '$SND_FIELD
fi
done < /tmp/art1
Errors:
SND_FIELD=200205281021_3cf3925c.137f.69_BW.html
+ 9416
rmb1.sh: 9416: not found
+ read LINE
+ echo 9496 200205281021_3cf3925c.137f.94_BW.html
+ cut -d -f 1
FST_FIELD=9496
+ echo 9496 200205281021_3cf3925c.137f.94_BW.html
+ cut -d -f 2
SND_FIELD=200205281021_3cf3925c.137f.94_BW.html
+ 9496
rmb1.sh: 9496: not found
+ read LINE
+ echo 5659 200205281021_3cf3925d.137f.148_BW.html
+ cut -d -f 1
FST_FIELD=5659
contents of /tmp/art1
4301 200206030418_3cfb5e62.3e6b.169.1.html
1710 200206030418_3cfb5e63.3e6b.170.1.html
5155 200206030443_3cfb6381.582d.51.2.html
6254 200206030443_3cfb6386.582d.53.2.html
4301 200206030443_3cfb638f.582d.58.2.html
4202 200206030443_3cfb63a1.582d.70.1.html
3817 200206030443_3cfb6457.582d.184.1_UPI.html
3119 200206030443_3cfb645a.582d.186.1.html
3833 200206030518_3cfb6b67.343.34.2.html
3599 200206030518_3cfb6b87.343.56.2.html
Script is failing to compare, any ideas?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2002 01:14 PM
06-03-2002 01:14 PM
Re: UNIX script help
if (( ${FST_FIELD} < 1100 ))
to
if [ ${FST_FIELD} -lt 1100 ]
then
....
....
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2002 01:17 PM
06-03-2002 01:17 PM
Re: UNIX script help
echo 'First field = '$FST_FIELD' Second Field = '$SND_FIELD
should be
echo "First field = \"${FST_FIELD}\" Second Field = \"${SND_FIELD}\""
You want the shell to interpret the values, hence " rather than '.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2002 01:29 PM
06-03-2002 01:29 PM
Re: UNIX script help
#!/usr/bin/sh
typeset -i i=0
if [ $# -eq 2 ]
then
if [ -s $1 ]
then
while read i line
do
if [ $i -lt 1100 ]
then
echo $line
fi
done < $1 > $2
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 12:16 AM
06-04-2002 12:16 AM
Re: UNIX script help
awk is also a good tool for this type of problems. Try:
awk '$1 < 1100 { print $2 }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 12:49 AM
06-04-2002 12:49 AM
Re: UNIX script help
two mistakes in your script:
if [ $FST_FIELD -lt 1100 ]
then
echo "First field = $FST_FIELD Second Field = $SND_FIELD"
......
will do it for you.
Allways stay on the bright side of life!
Peter