- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script - for loop statement
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
тАО09-10-2008 02:11 AM
тАО09-10-2008 02:11 AM
I have file:
0011
5566
1265
7889
7878
I should match pattern aabb so that output could be:
0011
5566
so far I did this:
set -A arr `echo "0:1:2:3:4:5:6:7:8:9" | nawk -F":" '{for(i=1;i<=NF;i++) print $i}'`
for num in ${arr[@]}
do
grep $num$num00 tmp
grep $num$num11 tmp
grep $num$num22 tmp
grep $num$num33 tmp
grep $num$num44 tmp
grep $num$num55 tmp
grep $num$num66 tmp
grep $num$num77 tmp
grep $num$num88 tmp
grep $num$num99 tmp
done
is there more effective way?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 02:14 AM
тАО09-10-2008 02:14 AM
Re: shell script - for loop statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 02:25 AM
тАО09-10-2008 02:25 AM
Re: shell script - for loop statement
also I tryed this one..
#!/bin/ksh
k=0
l=0
while [ $k -lt 10 ]; do
while [ $l -lt 10 ]; do
grep $k$k$l$l tmp
l=`expr $l + 1`
done
k=`expr $k + 1`
done
again stupid result..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 02:58 AM
тАО09-10-2008 02:58 AM
Re: shell script - for loop statement
try this one:
$ grep "\([0-9]\)\1\([0-9]\)\2" file
and see regexp(5)
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 03:13 AM
тАО09-10-2008 03:13 AM
Re: shell script - for loop statement
Or you could use perl...
Create the script match.pl
#!/usr/bin/perl
while (
($a, $b) = /(.).(.)./;
print $_ if ($_ =~ /$a$a$b$b/);
}
and put your numbers in match.txt
Execute with
cat match.txt | match.pl
Don't forget to make your match.pl executable!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 03:40 AM
тАО09-10-2008 03:40 AM
Re: shell script - for loop statement
Hemmetter that was nice..but also with this grep numbers 7777 and 3333 and 1111 etc. are also colected..but they should not be taken.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 03:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 04:06 AM
тАО09-10-2008 04:06 AM
Re: shell script - for loop statement
it is as easy as:
$ grep "\([0-9]\)\1\([0-9]\)\2" tmp | grep -v "\([0-9]\)\1\1\1"
Rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 04:18 AM
тАО09-10-2008 04:18 AM
Re: shell script - for loop statement
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2008 09:05 AM
тАО09-10-2008 09:05 AM
Re: shell script - for loop statement
> no perl please...
Why? Perl runs on virtually any kind of platform you can find --- that "other" operating system, too.
A shell script can just as easily run a Perl snippet as it can a 'grep' process.
All that aside, here's a regular expression in Perl (using negative look-ahead) to do your job:
# X="0011\n5566\n1265\n7889\n7878" #...your data
# echo ${X} | perl -ne 'print if m{ ((^\d)\2) (?!\2) }x'
0011
5566
Regards!
...JRF...