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

  • Home
  • SEARCH
  • 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 8625269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:44:31+00:00 2026-06-12T07:44:31+00:00

grep -A 26 some text somefile.txt | awk ‘/other text/ { gsub(/M/, ); print

  • 0
grep -A 26 "some text" somefile.txt |
   awk '/other text/ { gsub(/M/, " "); print $4 }' |
   sort -n -r | uniq | head -1

will return the largest in a list pulled from a large text file, but how do I store the output as a variable?

  • 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-12T07:44:32+00:00Added an answer on June 12, 2026 at 7:44 am

    Use command substitution:

    my_var=$(grep -A 26 "some text" somefile.txt |
       awk '/other text/ { gsub(/M/, " "); print $4 }' |
       sort -n -r | uniq | head -n1)
    

    Also, for portability, I would suggest always using -n1 for the argument of head. I’ve come across a couple of incarnations of it where using -1 doesn’t work.

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

Sidebar

Related Questions

grep -A 26 some text somefile.txt | awk '/other text/ { gsub(/M/, ); print
I want to grep a particular string from a text file at some location
Assuming sentence The time is now 8:15pm. Followed by some other text Why would
I'm looking for some pattern in 1.txt out of 2.txt, using grep . Then
We use grep, cut, sort, uniq, and join at the command line all the
Example: ... Line some text other text 10 ... Is it possible to tell
Background: sometimes I use ps aux | grep process_name to figure out some statistics
I have managed to run hadoop examples grep, wordcount... however I am finding some
In my program, I'm grep-ing via NSTask. For some reason, sometimes I would get
I want to grep files that contain text "wp_" but do not contain text

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.