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 7886487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:19:50+00:00 2026-06-03T05:19:50+00:00

Details: I am reading a file in an incoming stream using tail -f I

  • 0

Details:

I am reading a file in an incoming stream using tail -f

I am able to find and replace characters/strings in the stream using sed, something like:

tail -f a.log | sed 's/'`echo -e "\xnn"`'/'`echo "$(tput setaf 1)|sep|$(tput sgr0)"`'/g'

What the above achieves is give me a clear visual marker for the separator string (which is non-printable hex character nn in this case, nn might be 05 as an example, replacing it with a red (in this case) colored (via tput) string |sep|.

So I get something like

field **|sep|** field **|sep|** field **|sep|**

What I want is

field **|sep#1|** field **|sep#2|** field **|sep#3|**

So, the requirement is to have the nth match marked as such in the substitution string (|sepn| where n is the no. of match encountered)

  • 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-06-03T05:19:51+00:00Added an answer on June 3, 2026 at 5:19 am

    Use Perl’s ability to evaluate replacement on the fly to keep track of number of replacements made:

    my $str='field **|sep|** field **|sep|** field **|sep|**';
    my $str2='saodifuasd|sep|psaoidugfsdoif|sep|sdoiufd';
    my $cnt;
    $cnt=0; $str=~s/\|sep\|/"|sep#".$cnt++."|"/ge;
    $cnt=0; $str2=~s/\|sep\|/"|sep#".$cnt++."|"/ge;
    print "$str\n";
    print "$str2\n";
    

    Result:

    field **|sep#0|** field **|sep#1|** field **|sep#2|**
    saodifuasd|sep#0|psaoidugfsdoif|sep#1|sdoiufd
    

    As you see, you will have to manually reset separator counter on every line.

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

Sidebar

Related Questions

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
Once again I have hit the wall. How to replace escape characters using regular
I would like to view a pdf file in a split window using gVim,
The details of the contacts not displayed properly by using this code. I am
I have a php site. I have a flat file for reading selections to
I need to retrieve some details from a MusicXML (xml) file in Java. I
I want to find a string in a txt file if string compares, it
I am trying to write a chunk of XML data to a file like
I'm reading an XML file from a REST web service, parsing it, and displaying
I'm reading a rss feed using simple code: <?php $homepage = file_get_contents('http://www.forbes.com/news/index.xml'); $movies =

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.