Sponsored Content
Top Forums UNIX for Advanced & Expert Users How to limit the search to 'n' occurrences within a line Post 302350164 by Linuxee on Thursday 3rd of September 2009 02:53:45 AM
Old 09-03-2009
Question Not working for me :-(

Hello malcomex999, Vi-Curious,

Thanks for the replies.I tried both the suggestions but none of them worked for me :-(. My file contains -

~/Desktop$ cat b.txt
hello hello hello hello
good morning
good evening

I am trying to search for hello string in this file and am expecting it to print 'hello' only twice in the output. Please let me know if i am doing something wrong there.

~/Desktop$ awk -v var="hello" '{str=$0;cnt=gsub(var,arr);if(cnt==2)print str}' b.txt
<No OutPut here>

~/Desktop$ perl -nle '{print $_ if scalar(@_ == $_ =~ /hello/g) == 2}' b.txt
<No OutPut here>

Regards.



 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep line length limit

Hi Friends, I am having a funny problem with grep. When I run grep 'expr' file.txt things work fine. But when try to get the line number using the -n option, i.e, grep -n 'expr' file.txt I get a message, "grep: 0652-226 Maximum line length of 2048 exceeded." If the line has more than... (3 Replies)
Discussion started by: hnhegde
3 Replies

2. UNIX for Dummies Questions & Answers

Search and Count Occurrences of Pattern in a File

I need to search and count the occurrences of a pattern in a file. The catch here is it's a pattern and not a word ( not necessarily delimited by spaces). For eg. if ABCD is the pattern I need to search and count, it can come in all flavors like (ABCD, ABCD), XYZ.ABCD=100, XYZ.ABCD>=500,... (6 Replies)
Discussion started by: tektips
6 Replies

3. Shell Programming and Scripting

sed replace multiple occurrences on the same line, but not all

Hi there! I am really enjoying working with sed. I am trying to come up with a sed command to replace some occurrences (not all) in the same line, for instance: I have a command which the output will be: 200.300.400.5 0A 0B 0C 01 02 03 being that the last 6 strings are actually one... (7 Replies)
Discussion started by: ppucci
7 Replies

4. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

5. Shell Programming and Scripting

sed: how to limit pattern search to first instance only

I need to reduce a file's size below 50MB by deleting chucks of text. The following sed does this. sed '/^begpattern/,/endpattern/d' myfile However, it's possible that the file size can get below 50MB by just deleting the first instance of the pattern. How do I code that into sed? Or can awk... (8 Replies)
Discussion started by: mariod1049
8 Replies

6. Shell Programming and Scripting

grep by limit search

Hi I am in new in unix,can any one tell how to grep the data by limit. suppose I have below data:- is :mSecs is :mSecs is :mSecs is :mSecs requirement is how to grep the data which is having count greater than 1000 msecs only. thanks in adnavce. (2 Replies)
Discussion started by: abhigrkist
2 Replies

7. Programming

Limit line for perl

Hey guys, can help me out with this? How do i limit output for xml to 50 character? i tried *below* but doesnt work, it still print more than 50 characters. Thanks in advance printf "%-50s", "$testline\n"; (4 Replies)
Discussion started by: Nick1097
4 Replies

8. Shell Programming and Scripting

How to search number of occurrences of a particular string in a file through vi editor?

i have one file, i am doing 'vi Filename' now i want to search for particular string and i want to know how many times that string occurs in whole file (5 Replies)
Discussion started by: sheelsadan
5 Replies

9. UNIX for Advanced & Expert Users

sed REGEX to print multiple occurrences of a pattern from a line

I have a line that I need to parse through and extract a pattern that occurs multiple times in it. Example line: getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed,... (4 Replies)
Discussion started by: Vidhyaprakash
4 Replies

10. Shell Programming and Scripting

Delete multiple occurrences of the same pattern on a line but the first

The lines that I am trying to format look like Device ID: j01-01, IP address: 10.10.10.36, IP address: 10.10.10.35, IP address: 10.10.102.201, Platform: 8040, Capabilities: Host , Interface: GigabitEthernet9/45, Port ID (outgoing port): e0k,Here is what I have so far but it... (4 Replies)
Discussion started by: dis0wned
4 Replies
Desktop::Notify(3pm)					User Contributed Perl Documentation				      Desktop::Notify(3pm)

NAME
Desktop::Notify - Communicate with the Desktop Notifications framework VERSION
Version 0.03 SYNOPSIS
use Desktop::Notify; # Open a connection to the notification daemon my $notify = Desktop::Notify->new(); # Create a notification to display my $notification = $notify->create(summary => 'Desktop::Notify', body => 'Hello, world!', timeout => 5000); # Display the notification $notification->show(); # Close the notification later $notification->close(); DESCRIPTION
This module provides a Perl interface to the Desktop Notifications framework. The framework allows applications to display pop-up notifications on an X desktop. This is implemented with two components: a daemon that displays the notifications, and a client library used by applications to send notifications to the daemon. These components communicate through the DBus message bus protocol. More information is available from <http://trac.galago-project.org/wiki/DesktopNotifications> This module serves the same purpose as "libnotify", in an object-oriented Perl interface. It is not, however, an interface to "libnotify" itself, but a separate implementation of the specification using Net::DBus. METHODS
new %opts Connect to the notification daemon. %opts can include the following options: app_name The application name to use for notifications. Default is "basename($0)" bus The Net::DBus mesage bus to use. Default is to call Net::DBus->session, which is usually where notification-daemon can be reached. service The DBus service name of the daemon. Default is org.freedesktop.Notifications. objpath The path to the notifications DBus object. Default is /org/freedesktop/Notifications. objiface The DBus interface to access the notifications object as. Default is org.freedesktop.Notifications. create %params Creates a new notification object that can be displayed later. This will return a Desktop::Notify::Notification object; see that module for information about using it. close_callback $coderef Sets a user-specified function to be called whenever a notification is closed. It will be called with one argument, which is the Notification object that was just closed. AUTHOR
Stephen Cavilia, "<sac at atomicradi.us>" SEE ALSO
Net::DBus <http://www.galago-project.org/specs/notification/index.php> <http://www.galago-project.org/downloads.php> BUGS
Please report any bugs or feature requests to "bug-desktop-notify at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Desktop-Notify>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Desktop::Notify You can also look for information at: o AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/Desktop-Notify> o CPAN Ratings <http://cpanratings.perl.org/d/Desktop-Notify> o RT: CPAN's request tracker <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Desktop-Notify> o Search CPAN <http://search.cpan.org/dist/Desktop-Notify> ACKNOWLEDGEMENTS
COPYRIGHT &; LICENSE Copyright 2007 Stephen Cavilia, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2009-12-24 Desktop::Notify(3pm)
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy