Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:14:39+00:00 2026-05-31T04:14:39+00:00

I am looking for a way to create a bash script, using possibly sed

  • 0

I am looking for a way to create a bash script, using possibly sed or awk, to search for a particular string of text, say “Deprecated from: 4.*”. If found, the script should then take the text found between two patterns, backup the text to a file, then remove the text from the original input file. In summary I am looking for a way to filter out certain deprecated portions of a very large MIB file that is structured like this one:

-- /*********************************************************************************/
-- /* MIB table for foo 'Something that was once very cool                         */
-- /* Valid from: 4.1.01                                                            */
-- /* Valid to: 4.2                                                                 */
-- /* Deprecated from: 4.2                                                          */
-- /*********************************************************************************/

foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar      
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 

-- /*********************************************************************************/
-- /* MIB table for bar 'Another thing that was once very cool                         */
-- /* Valid from: 4.2.01                                                            */
-- /* Valid to: 4.3                                                                 */
-- /* Deprecated from: 4.3                                                          */
-- /*********************************************************************************/

foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar      
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 

So, in this case let’s say I want to get rid of the section containing “Deprecated from 4.2”. I have come up with the following awk script which gets me closer:

{ a[i++ % 5 ]=$0} 
/Deprecated from: 4.2/ {print a[(i-5)%5];print a[(i-4)%5];print a[(i-3)%5];print a[(i-2)%5];i=0}
/Deprecated from: 4.2/,/test/ {if($0 !~ /test/) print }

However this only works if the MIB uses the word “test” as the last part of the range to search for. In reality the end of the search range is as follows:

-- /*********************************************************************************/

What I need to do is skip the first instance of this, which occurs immediately after the line containing “Deprecated from” and continue searching on to the next occurrence.

Expected output after using the above MIB example, and removing all occurrences of 4.2, would be as follows:

-- /*********************************************************************************/
-- /* MIB table for bar 'Another thing that was once very cool                         */
-- /* Valid from: 4.2.01                                                            */
-- /* Valid to: 4.3                                                                 */
-- /* Deprecated from: 4.3                                                          */
-- /*********************************************************************************/

foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar      
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar  
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 
foo bar foo bar foo bar foo bar foo bar foo bar foo bar 

See an example of the above code working here: http://ideone.com/bOQuK

My problem is I need to search for the closing pattern of

-- /*********************************************************************************/

Not:

-- /test/

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:14:40+00:00Added an answer on May 31, 2026 at 4:14 am

    the proper usage of RS with awk could solve your problem:

    awk  'BEGIN{RS="-- /[\x2a]*/";} 
    { if(NR%2==0)x= ($0!~/Deprecated from: 4\.2/)?1:0;  
      if(x)if(NR%2==0)print RT, $0,RT; else print $0}' yourFile
    

    see the test below:

    I changed the content(foo bar) in your example to distinguish the text from which block:

    kent$  cat big.txt 
    -- /*********************************************************************************/
    -- /* MIB table for foo 'Something that was once very cool                         */
    -- /* Valid from: 4.1.01                                                            */
    -- /* Valid to: 4.2                                                                 */
    -- /* Deprecated from: 4.2                                                          */
    -- /*********************************************************************************/
    
              ##
              ####
              ##   #
          #   ##     ##
          ###############
          #################
          #   ## 
           #
          ###
    
          #
          ####             
          ### ##          #
          ###  ##           
          ###    ##       # 
          ###    ####   ###
          ###      #######
             #
    -- /*********************************************************************************/
    -- /* MIB table for bar 'Another thing that was once very cool                         */
    -- /* Valid from: 4.2.01                                                            */
    -- /* Valid to: 4.3                                                                 */
    -- /* Deprecated from: 4.3                                                          */
    -- /*********************************************************************************/
    
              ##
              ####
              ##   #
          #   ##     ##
          ###############
          #################
          #   ## 
           #
          ###
    
    
           #             # 
          #               #
          #                 
          ##       ##     #
           ###  ### #######
            ######    ###
    

    run the awk line:

    kent$  awk  'BEGIN{RS="-- /[\x2a]*/";} { if(NR%2==0)x= ($0!~/Deprecated from: 4\.2/)?1:0;  if(x)if(NR%2==0)print RT, $0,RT; else print $0}' big.txt
    -- /*********************************************************************************/ 
    -- /* MIB table for bar 'Another thing that was once very cool                         */
    -- /* Valid from: 4.2.01                                                            */
    -- /* Valid to: 4.3                                                                 */
    -- /* Deprecated from: 4.3                                                          */
     -- /*********************************************************************************/
    
    
              ##
              ####
              ##   #
          #   ##     ##
          ###############
          #################
          #   ## 
           #
          ###
    
    
           #             # 
          #               #
          #                 
          ##       ##     #
           ###  ### #######
            ######    ###
    

    Note that the backup part is not included. however it is easy to be added. since in my script, the text should not be shown (need to be saved to anoter file as backup) is already marked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to create a switch for this bash script so
I'm looking for a way to (hopefully) create a text file which lists all
I'm looking for the best way to create a unique ID as a String
I am looking for a way to create a new VPN connection using only
I'm looking for a way to create a GUI (using Cocoa) to make a
I am looking for a way to create a string variable containing certain values
I'm looking for a way to create elements form string eg this doesnt work:
a few weeks ago i was looking for a way to create some String
I am looking for a way to create a script component within SSIS which
I'm looking for a way to create a dynamic list below a text field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.