- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk 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
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
тАО10-01-2003 06:16 PM
тАО10-01-2003 06:16 PM
attached a file from which I want to print out/extract only the BTS numbers under BTS column - at the end of the file, in this case 002,003,006. I want to filter out the BTS names - CITY2, METRO2 and all the other lines.It should be possible with awk but I'm still not that good :-)
Any idea?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 07:38 PM
тАО10-01-2003 07:38 PM
Re: awk script help!
how about a semi-awk construction:
# grep -e "[0-9]*\ *[0-9]*CITY2\ *[0-9]*\ *METRO2"
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 07:40 PM
тАО10-01-2003 07:40 PM
Re: awk script help!
#!/usr/bin/perl
@DATA=`cat datafile`;
while($i=shift @DATA){
if($i =~ /BTS NAME/){
shift @DATA;
$line=shift @DATA;
($num1,$num2,$num3,$num4)=split " ",$line;
print "$num1 $num2 $num4\n";
exit 0;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 08:39 PM
тАО10-01-2003 08:39 PM
Re: awk script help!
2. The perl script doesn't work - at line 8, next 2 tokens split " " - compilation error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 09:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 09:13 PM
тАО10-01-2003 09:13 PM
Re: awk script help!
if only the BTS columns have a 3 digits format, here is a solution using sed:
# grep ^[0-9][0-9][0-9][^0-9] test|sed -e 's/[0-9][0-9][0-9]/\
/g'
gives the result:
CITY2
METRO2
Please note that the substitution is on two lines, and that the \ on the first line indicates that the substitution is to continue on next line: it is
sed -e 's/[0-9][0-9][0-9]/\
/g'
and not
sed -e 's/[0-9][0-9][0-9]/\/g'
Hope this helps,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 10:05 PM
тАО10-01-2003 10:05 PM
Re: awk script help!
I just downloaded your example and did a cut and paste of the code from my browser, ran the script and this is what I got.
bash-2.05a$ mv 17329.null datafile
bash-2.05a$ ./script.pl
002 003 006
Perhaps your cut and paste put a newline somwhere in this line
($num1,$num2,$num3,$num4)=split " ",$line;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 10:08 PM
тАО10-01-2003 10:08 PM
Re: awk script help!
If that's your requirement, then this will do it.
Save to a file (eg my.awk), and use
awk -f my.awk 17329.null
BEGIN {btsfound=0}
/^BTS NAME/ {btsfound=1}
/^--/ {next}
/^[:space:]*$/ {print ; btsfound=0} # Look for whitespace
(btsfound==1) {
for (i=1; i<=NF; i++) {
if (match($i,"^[0-9][0-9][0-9]$") != 0)
printf ("%s ", $i)
}
}
They will all be printed on one-line, space separated. Adjust the printf statements to suit your taste...
Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 11:08 PM
тАО10-01-2003 11:08 PM
Re: awk script help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2003 11:35 PM
тАО10-01-2003 11:35 PM
Re: awk script help!
I have re-tried your perl script - I have tried with copy and paste I have written it by hand in vi - nothing! I got the same compilation error in line 8. My Perl is 5.005_03 I have to use this version!