Sponsored Content
Top Forums Shell Programming and Scripting bash: need to have egrep to return a text string if the search pattern has NOT been found Post 302669283 by agama on Tuesday 10th of July 2012 08:33:36 PM
Old 07-10-2012
This is how I would have approached it:

Code:
awk -F . '
    function dump( )
    {
        if( stuff["article"] )
            printf( "%s %s %s %s %s\n", stuff["article"], stuff["colour"], stuff["number"], stuff["name"], stuff["month"] );
        else
            printf( "Article Colours Numbers Names Month\n" );
        delete stuff;
    }

    /^article/ {
        dump( );
        stuff["article"] = $NF;
        next;
    }

    { stuff[$1] = $NF; }

    END { dump(); }

' input-file

EDIT: Crossed with Methyl; I made the assumption that the 'article' could be treated as a division. Of course, if that assumption is wrong it all goes out the window.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Using egrep to search for Text and special char

Anyone is well-versed to use egrep to search a file for a line containing both: 1) AAA 2) $ I am having problem escaping the dollar sign when using egrep in conjunction with satisfying AAA as well. E.g. Text file Line 1 AAA Line 2 $$$ Line 3 AAA BBB $ Line 4 $$$ BBB AA will return me... (2 Replies)
Discussion started by: izy100
2 Replies

2. Shell Programming and Scripting

Help with pattern search and return

I would like to write a script which will read a file containing a list of filenames of the format as shown below : /usr/local/packages/runcmdlinetool /home/john.doe/sdfsdf/sdfsdfsd/sdfsdf/sdfsdfTemplates.xml /usr/local/bin/gtar... (4 Replies)
Discussion started by: inditopgun
4 Replies

3. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

4. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

5. UNIX for Dummies Questions & Answers

Search specific pattern in file and return number of occurence

Hi I want to search for a specific pattern in file Say ABC;HELLO_UNIX_WORLD;PQR ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ ABC;HELLO_UNIX_FORUM;LMN Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_" I mean after "HELLO_UNIX" there can only be one word.In this case... (2 Replies)
Discussion started by: dashing201
2 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. Shell Programming and Scripting

Avoid carriage return until ^M is found (CentOS 6, bash 4.1)

Hi everyone, I have the following contents in a text file (as seen when viewed using vim): one two three ^M four five six ^M seven eight nine ^M ten eleven twelve ^M (That is just a small portion of the file) How can I obtain the following result? one two three ^M four five six ^M seven... (2 Replies)
Discussion started by: gacanepa
2 Replies

8. UNIX for Dummies Questions & Answers

How to find a file based on pattern & return the filename if found?

Hi all, I am a newbie here. I have this requirement to find a file based on a pattern then return the filename if found. I created a script based on online tutorials. Though, I am stuck & really appreciate if anyone can have a quick look & point me to the right direction? #Script starts... (10 Replies)
Discussion started by: buster_t
10 Replies

9. Shell Programming and Scripting

Search a text and return the text from file

Hi I have a set of input strings in a pattern as given below string1 string2 string3 string4 string5 I need to search this sequence of strings from a file in such a way that the first two strings (string1 and string2) and last two strings (string4 and string5) should match with the... (8 Replies)
Discussion started by: my_Perl
8 Replies

10. Shell Programming and Scripting

Bash to search file for string and lauch function if found

In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK. If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the file is sent to the... (2 Replies)
Discussion started by: cmccabe
2 Replies
EXPIRE.CTL(5)							File Formats Manual						     EXPIRE.CTL(5)

NAME
       expire.ctl - control file for Usenet article expiration

DESCRIPTION
       The  file  /etc/news/expire.ctl	is  the default control file for the expire(8) program, which reads it at start-up.  Blank lines and lines
       beginning with a number sign (``#'') are ignored.  All other lines should be in one of two formats.

       The first format specifies how long to keep a record of fully-expired articles.	This is useful when a newsfeed intermittently offers older
       news  that  is  not kept around very long.  (The case of very old news is handled by the ``-c'' flag of innd(8).)  There should only be one
       line in this format, which looks like this:
	      /remember/:days
       Where days is a floating-point number that specifies the upper limit to remember a Message-ID, even if the  article  has  already  expired.
       (It does not affect article expirations.)

       Most of the lines in the file will consist of five colon-separated fields, as follows:
	      pattern:modflag:keep:default:purge
       The  pattern  field  is a list of wildmat(3)-style patterns, separated by commas.  This field specifies the newsgroups to which the line is
       applied.  Note that the file is interpreted in order, so that the last line that matches will be used.  This means  that  general  patterns
       (like a single asterisk to set the defaults) should appear before specific group specifications.

       The modflag field can be used to further limit newsgroups to which the line applies, and should be chosen from the following set:
	      M    Only moderated groups
	      U    Only unmoderated groups
	      A    All groups

       The  next  three  fields are used to determine how long an article should be kept.  Each field should be either a number of days (fractions
       like ``8.5'' are allowed) or the word ``never.''  The most common use is to specify the default value for how long  an  article	should	be
       kept.   The  first  and	third fields -- keep and purge -- specify the boundaries within which an Expires header will be honored.  They are
       ignored if an article has no Expires header.  The fields are specified in the file as ``lower-bound default  upper-bound,''  and  they  are
       explained  in this order.  Since most articles do not have explicit expiration dates, however, the second field tends to be the most impor-
       tant one.

       The keep field specifies how many days an article should be kept before it will be removed.  No article in the newsgroup will be removed if
       it  has	been filed for less then keep days, regardless of any expiration date.	If this field is the word ``never'' then an article cannot
       have been kept for enough days so it will never be expired.

       The default field specifies how long to keep an article if no Expires header is present.  If this field is the word ``never'' then articles
       without explicit expiration dates will never be expired.

       The purge field specifies the upper bound on how long an article can be kept.  No article will be kept longer then the number of days spec-
       ified by this field.  All articles will be removed after then have been kept for purge days.  If purge is the word ``never'' then the arti-
       cle will never be deleted.

       It  is  often  useful  to  honor  the  expiration headers in articles, especially those in moderated groups.  To do this, set keep to zero,
       default to whatever value you wish, and purge to never.	To ignore any Expires header, set all three fields to the same value.

       There must be exactly one line with a pattern of ``*'' and a modflags of ``A'' -- this matches all groups and is used to set the expiration
       default.  It should be the first expiration line.

       For example,
	      ##  How long to keep expired history
	      /remember/:5
	      ##  Most things stay for two weeks
	      *:A:14:14:14
	      ##  Believe expiration dates in moderated groups, up to six weeks
	      *:M:1:30:42
	      ##  Keep local stuff for a long time
	      foo.*:A:30:30:30

HISTORY
       Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews.  This is revision 1.15, dated 1996/10/29.

SEE ALSO
       expire(8), wildmat(3).

																     EXPIRE.CTL(5)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy