- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting question
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
03-12-2003 06:31 AM
03-12-2003 06:31 AM
Im trying to write a script either in awk or in ksh to read in a text file with a format like shown below:
......start....
sht 2 3 4
trc 4 5 5
trc 3 3 2
trc 2 3 4
trc 3 4 1
trc 1 3 6
trc 3 3 5
trc 4 3 1
trc 2 3 5
sht 1 6 3
trc 4 5 5
trc 3 3 2
trc 2 3 4
trc 3 4 1
trc 1 3 6
trc 3 3 5
trc 4 3 1
trc 2 3 5
.........end.........
It is a really long file with similar format. All I want to do is to read in the file and print the line that starts with "sht" and every fourth line that starts with "trc"
Could somebody help me please
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 06:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 06:41 AM
03-12-2003 06:41 AM
Re: scripting question
cat t|while true
do
read A B C D
[ "$A" = "" ] && exit
[ "$A" = "sht" ] && echo $A $B $C $D
if [ "$A" = "trc" ]
then
let x=$x+1
if [ $x -eq 4 ]
then
echo $A $B $C $D
let x=0
fi
fi
done
where t (on 2nd line in cat t) is the name of the input file with all your data in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 06:44 AM
03-12-2003 06:44 AM
Re: scripting question
It is very close.
I actually want to print every fourth occurence of lines begining with "trc"
Thanks a lot again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 06:47 AM
03-12-2003 06:47 AM
Re: scripting question
awk '/^sht/{print}/^trc/{count++;if (count==4){print;count=0}}' file
this resets the counter after 4 occurrences of trc at the beginning of the line.
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 06:56 AM
03-12-2003 06:56 AM
Re: scripting question
file=$1
typeset -i x=1
cat $file|while read a b c d
do
case $a in
sht) echo $a $b $c $d ;;
trc) if [ "$x" -eq "4" ]
then
let x=1
echo $a $b $c $d
else
typeset -i x=$x+1
fi ;;
esac
done
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2003 07:28 AM
03-12-2003 07:28 AM
Re: scripting question
sht 2 3 4
trc 3 4 1
trc 2 3 5
sht 1 6 3
trc 3 4 1
trc 2 3 5
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 09:31 PM
03-13-2003 09:31 PM
Re: scripting question
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 10:09 PM
03-13-2003 10:09 PM
Re: scripting question
FYI:
x % y
Remainder. The quotient is rounded toward zero to an integer, multiplied by y and this result is subtracted from x. This operation is sometimes known as "trunc-mod." The following relation always holds:
b * int(a / b) + (a % b) == a
One possibly undesirable effect of this definition of remainder is that x % y is negative if x is negative. Thus,
-17 % 8 = -1
hth
Yogeeraj