Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Searching for Multiple texts in a file Post 302586315 by m_usmanayub on Saturday 31st of December 2011 03:05:10 PM
Old 12-31-2011
Searching for Multiple texts in a file

Hello guys,

I hope anyone can help me with this ...

I have a file in which i have around 6000 lines of same format text like


1234567
2345678
3456789
....................

Now what I have to do is that there I have to search these numbers in another file which contains hundreds of thousands of records...

How can I search these numbers one by one and if found in that file print it to another output file.

Please help me with this problem.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching multiple files with multiple expressions

I am using a DEC ALPHA running Digital UNIX (formly DEC OSF/1) and ksh. I have a directory with hundreds of files that only share the extension .rpt. I would like to search that directory based on serial number and operation number and only files that meet both requirements to be printed out. I... (6 Replies)
Discussion started by: Anahka
6 Replies

2. UNIX for Advanced & Expert Users

Please Help. Need Help searching for multiple stings in a file and removing them.

Please help. Here is my problem. I have 9000 lines in file a and 500,000 lines in file b. For each line in file a I need to search file b and remove that line. I am currently using the grep -v command and loading the output into a new file. However, because of the size of file b this takes an... (2 Replies)
Discussion started by: mjs3221
2 Replies

3. Shell Programming and Scripting

searching thru or combining multiple lines in a unix file

This is the problem actually: This regex: egrep "low debug.*\".*\"" $dbDir/alarmNotification.log is looking for data between the two quotation marks: ".*\" When I hate data like this: low debug 2009/3/9 8:30:20.47 ICSNotificationAlarm Prodics01ics0003 IC... (0 Replies)
Discussion started by: ndedhia1
0 Replies

4. Shell Programming and Scripting

How to write a shell script to notify when certain texts appear in a file?

I have a server and occasionally the file mysqld.log would show something like /usr/libexec/mysqld: Disk is full writing './example_com_-_wordpress/wp_statpress.MYD' (Errcode: 122). Waiting for someone to free space... Retry in 60 secs How do I write a simple shell script to check mysqld.log... (1 Reply)
Discussion started by: acider
1 Replies

5. Shell Programming and Scripting

Perl, searching multiple files and printing returned line to new file

I am trying to find a way to utilise the full potential of my cpu cores and memory on my windows machine. Now, I am quite familiar with grep, however, running a Unix based OS is not an option right now. Unfortunately, the 32 bit grep for windows that I am running, I cannot run multiple... (1 Reply)
Discussion started by: Moloch
1 Replies

6. Shell Programming and Scripting

Searching for multiple patterns in a file

Hi All, I have a file in which i have to search for a pattern from the beginning of the file and if the pattern is found , then i have to perform a reverse search from that line to the beginning of the file to get the first occurrence of another pattern. sample input file hey what are you... (8 Replies)
Discussion started by: Kesavan
8 Replies

7. Shell Programming and Scripting

Nawk help searching for multiple lines and multiple searches

I use this command to find a search (Nr of active alarms are) and print one line before and 10 lines after the search keywords. nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=1 a=10 s="Nr of active alarms are:" *.log However, I would like to know how to tell it to print... (3 Replies)
Discussion started by: tthach830
3 Replies

8. Shell Programming and Scripting

Help in searching a multiple text in zip file

Hi Gurus, i have 8 zipped files and each file is having more than 100,000 records or more. issue :- i want to search the missing text from each zipped files i have stuck here, the below command works fine if i give the value 10 for the deptno. if i have more than 1 records... (6 Replies)
Discussion started by: SeenuGuddu
6 Replies

9. Shell Programming and Scripting

How to combine 2 texts file and create another file from it?

Hi all, I've the following hostnames & ip addresses saved in host_ip.txt Based on this list, I need to create the following script. where by HH is a hostname and XXXX is an ip address So the final output would be something like this. Currently, I'm doing it manually, replace, copy... (3 Replies)
Discussion started by: type8code0
3 Replies

10. Shell Programming and Scripting

Serach a string for multiple occurrences in a file and cut related texts

Hi, I want a help in this forum for my below issue. 1. I have a file where I'm searching for a text . 2. When I get the line where the above string is present I want to cut some texts from the line where the particular string was found. These above two steps will repeat in the... (2 Replies)
Discussion started by: bhaski2012
2 Replies
Term::Sk(3pm)						User Contributed Perl Documentation					     Term::Sk(3pm)

NAME
Term::Sk - Perl extension for displaying a progress indicator on a terminal. SYNOPSIS
use Term::Sk; my $ctr = Term::Sk->new('%d Elapsed: %8t %21b %4p %2d (%8c of %11m)', {quiet => 0, freq => 10, base => 0, target => 100, pdisp => '!'}); $ctr->up for (1..100); $ctr->down for (1..100); $ctr->whisper('abc'); my last_line = $ctr->get_line; $ctr->close; print "Number of ticks: ", $ctr->ticks, " "; EXAMPLES
Term::Sk is a class to implement a progress indicator ("Sk" is a short form for "Show Key"). This is used to provide immediate feedback for long running processes. A sample code fragment that uses Term::Sk: use Term::Sk; print qq{This is a test of "Term::Sk" }; my $target = 2_845; my $format = '%2d Elapsed: %8t %21b %4p %2d (%8c of %11m)'; my $ctr = Term::Sk->new($format, {freq => 10, base => 0, target => $target, pdisp => '!'}); for (1..$target) { $ctr->up; do_something(); } $ctr->close; sub do_something { my $test = 0; for my $i (0..10_000) { $test += sin($i) * cos($i); } } Another example that counts upwards: use Term::Sk; my $format = '%21b %4p'; my $ctr = Term::Sk->new($format, {freq => 's', base => 0, target => 70}); for (1..10) { $ctr->up(7); sleep 1; } $ctr->close; At any time, after Term::Sk->new(), you can query the number of ticks (i.e. number of calls to $ctr->up or $ctr->down) using the method 'ticks': use Term::Sk; my $ctr = Term::Sk->new('%6c', {freq => 's', base => 0, target => 70}); for (1..4288) { $ctr->up; } $ctr->close; print "Number of ticks: ", $ctr->ticks, " "; This example uses a simple progress bar in quiet mode (nothing is printed to STDOUT), but instead, the content of what would have been printed can now be extracted using the get_line() method: use Term::Sk; my $format = 'Ctr %4c'; my $ctr = Term::Sk->new($format, {freq => 2, base => 0, target => 10, quiet => 1}); my $line = $ctr->get_line; $line =~ s/10/</g; print "This is what would have been printed upon new(): [$line] "; for my $i (1..10) { $ctr->up; $line = $ctr->get_line; $line =~ s/10/</g; print "This is what would have been printed upon $i. call to up(): [$line] "; } $ctr->close; $line = $ctr->get_line; $line =~ s/10/</g; print "This is what would have been printed upon close(): [$line] "; Here are some examples that show different values for option {num => ...} my $format = 'act %c max %m'; my $ctr1 = Term::Sk->new($format, {base => 1234567, target => 2345678}); # The following numbers are shown: act 1_234_567 max 2_345_678 my $ctr2 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9,999}}); # The following numbers are shown: act 1,234,567 max 2,345,678 my $ctr3 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9'99}}); # The following numbers are shown: act 1'23'45'67 max 2'34'56'78 my $ctr4 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9}}); # The following numbers are shown: act 1234567 max 2345678 my $ctr5 = Term::Sk->new($format, {base => 1234567, target => 2345678, commify => sub{ join '!', split m{}xms, $_[0]; }}); # The following numbers are shown: act 1!2!3!4!5!6!7 max 2!3!4!5!6!7!8 DESCRIPTION
Format strings The first parameter to new() is the format string which contains the following special characters: characters '%d' a revolving dash, format '/-|' characters '%t' time elapsed, format 'hh:mm:ss' characters '%b' progress bar, format '#####_____' characters '%p' Progress in percentage, format '999%' characters '%c' Actual counter value (commified by '_'), format '99_999_999' characters '%m' Target maximum value (commified by '_'), format '99_999_999' characters '%k' Token which updates its value before being displayed. An example use of this would be a loop wherein every step of the loop could be identified by a particular string. For example: my $ctr = Term::Sk->new('Processing %k counter %c', {base => 0, token => 'Albania'}); foreach my $country (@list_of_european_nations) { $ctr->token($country); for (1..500) { $ctr->up; ## do something... } }; $ctr->close; You can also have more than one token on a single line. Here is an example: my $ctr = Term::Sk->new('Processing %k Region %k counter %c', {base => 0, token => ['Albania', 'South']}); foreach my $country (@list_of_european_nations) { $ctr->token([$country, 'North']); for (1..500) { $ctr->up; ## do something... } }; $ctr->close; The "token" method is used to update the token value. If '%k' is used, then the counter must be instantiated with an intial value for the token. characters '%P' The '%' character itself Options The second parameter are the following options: option {freq => 999} This option sets the refresh-frequency on STDOUT to every 999 up() or down() calls. If {freq => 999} is not specified at all, then the refresh-frequency is set by default to every up() or down() call. option {freq => 's'} This is a special case whereby the refresh-frequency on STDOUT is set to every second. option {freq => 'd'} This is a special case whereby the refresh-frequency on STDOUT is set to every 1/10th of a second. option {base => 0} This specifies the base value from which to count. The default is 0 option {target => 10_000} This specifies the maximum value to which to count. The default is 10_000. option {pdisp => '!'} This option (with the exclamation mark) is obsolete and has no effect whatsoever. The progressbar will always be displayed using the hash-symbol "#". option {quiet => 1} This option disables most printing to STDOUT, but the content of the would be printed line is still available using the method get_line(). The whisper-method, however, still shows its output. The default is in fact {quiet => !-t STDOUT} option {num => '9_999'} This option configures the output number format for the counters. option {commify => sub{...}} This option allows one to register a subroutine that formats the counters. option {test => 1} This option is used for testing purposes only, it disables all printing to STDOUT, even the whisper shows no output. But again, the content of the would be printed line is still available using the method get_line(). Processing The new() method immediately displays the initial values on screen. From now on, nothing must be printed to STDOUT and/or STDERR. However, you can write to STDOUT during the operation using the method whisper(). We can either count upwards, $ctr->up, or downwards, $ctr->down. Everytime we do so, the value is either incremented or decremented and the new value is replaced on STDOUT. We should do so regularly during the process. Both methods, $ctr->up(99) and $ctr->down(99) can take an optional argument, in which case the value is incremented/decremented by the specified amount. When our process has finished, we must close the counter ($ctr->close). By doing so, the last displayed value is removed from STDOUT, as if nothing had happened. Now we are allowed to print again to STDOUT and/or STDERR. Post hoc transformation In some cases it makes sense to redirected STDOUT to a flat file. In this case, the backspace characters remain in the flat file. There is a function "rem_backspace()" that removes the backspaces (including the characters that they are supposed to remove) from a redirected file. Here is a simplified example: use Term::Sk qw(rem_backspace); my $flatfile = "Test hijabc101010xyzklmttt1010yzz"; printf "before (len=%3d): '%s' ", length($flatfile), $flatfile; rem_backspace($flatfile); printf "after (len=%3d): '%s' ", length($flatfile), $flatfile; AUTHOR
Klaus Eichner, January 2008 COPYRIGHT AND LICENSE
Copyright (C) 2008-2011 by Klaus Eichner This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-07-19 Term::Sk(3pm)
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy