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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:46:24+00:00 2026-06-17T13:46:24+00:00

I was reading this question Awk code to select multiple patterns The user has

  • 0

I was reading this question
Awk code to select multiple patterns

The user has this as input

------------------------------------------------------------------------
r4544 | n479826 | 2012-08-28 07:12:33 -0400 (Tue, 28 Aug 2012) | 1 line
Changed paths:
   M /branches/8.6.0/conf/src/main/config/RTSConfig.xml

CET-402: some text comment
------------------------------------------------------------------------
r4550 | n479826 | 2012-09-04 05:51:29 -0400 (Tue, 04 Sep 2012) | 1 line
Changed paths:
   M /branches/8.6.0/conf/src/main/config/RTSConfig.xml
   M /branches/8.6.0/conf/src/main/config/base.cfg
   M /branches/8.6.0/conf/src/main/config/prod.cfg
   M /branches/8.6.0/conf/src/main/config/qa.cfg
   M /branches/8.6.0/conf/src/main/config/uat.cfg

CET-438: some text comment

and he wants this as output

r4544 | n479826 | 2012-08-28 07:12:33 | /branches/8.6.0/conf/src/main/config/RTSConfig.xml
r4550 | n479826 | 2012-09-04 05:51:29 | /branches/8.6.0/conf/src/main/config/RTSConfig.xml
r4550 | n479826 | 2012-09-04 05:51:29 | /branches/8.6.0/conf/src/main/config/base.cfg
r4550 | n479826 | 2012-09-04 05:51:29 | /branches/8.6.0/conf/src/main/config/prod.cfg
r4550 | n479826 | 2012-09-04 05:51:29 | /branches/8.6.0/conf/src/main/config/qa.cfg
r4550 | n479826 | 2012-09-04 05:51:29 | /branches/8.6.0/conf/src/main/config/uat.cfg

The correct answer is this

awk -F"|" '/^r/{a=$1;b=$2;c=substr($3,0,20)}/^   M/{gsub(/   M /," ");print a"|"b"|"c"|"$0}' your_file

I didn’t understood that fully.

Now i got this part

/^r/{a=$1;b=$2;c=substr($3,0,20)}/^

but i didn’t get the second part
M/{gsub(/ M /," ");print a"|"b"|"c"|"$0}

My problems are

  1. What is M means in the beginning
    2.Now awk will read the file line by line so it means at the second line
    i.e Chngaed paths the value of a =0 because there is no field separator | on that line
  2. Now when the awk comes to third line
    then again a,b,c =0 and $0 = /bracnhes but how is the result still showing the old value of a,b,c

I am getting confused when awk is used on multi lines

  • 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-17T13:46:26+00:00Added an answer on June 17, 2026 at 1:46 pm

    I was lazy enough to explain the answer 🙂
    But lemme put my lazyness aside for some time now:

    /^r/{a=$1;b=$2;c=substr($3,0,20)}
    

    The above block of code will execute only when the line starts with a letter r.
    inside the block says store the first field in a ,second field in b and third field from input is :

    2012-08-28 07:12:33 -0400 (Tue, 28 Aug 2012)
    

    but i need only the date with timestamp and the rest is obsolete for me.
    it is always 20 characters.
    so i took a substring from the third field and stored it in c.

    my main interest was the line which starts with /^ M/ which i have to display with the information present in the previous line which start with r
    and for sure there is a line which starts with r before our desired line which has all the information i have to prepend the lines which start with M.

    so every time a line starts with M will be prepended with the values stored in a b and c.

    M/{gsub(/ M /," ");print a"|"b"|"c"|"$0}
    

    gsub part will remove the part of ” M ” with a space from the current line.
    print part just prepends the value of a b and c to the current line with | as teh separator.

    This what the logic is!

    I will be back into my lazy mode now 🙂

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

Sidebar

Related Questions

Note: Before reading this question and its answer, please check your input element has
Reading this question I found this as (note the quotation marks) code to solve
While reading this question I wanted to test the input in GCC to see
thanks for reading this question. Basically I am trying to do a code that
After reading this question , my first reaction was that the user is not
I was reading this question , I wanted to ask more about the code
Thank you for reading this Question. CODE BELOW I'm trying to get a jsp
After reading this question, I need to clear up some things. IQueryable<Customer> custs =
After reading this question , i saw the answer by Naveen containing a link
I was reading this question, but didn't understand some part of the aix's answer

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.