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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:28:51+00:00 2026-06-05T06:28:51+00:00

file.txt is as below : gui : 789 gui : 789 gui : 789

  • 0

file.txt is as below :

gui : 789
gui : 789
gui : 789
gui : 789
abc : 120

The followibng gives o/p as

$ grep -n "gui : 789" file.txt | cut -f1 -d: 
1
2
3
4

If there are N number of such gui : 789 , how to store the line numbers of the same ?

  • 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-05T06:28:55+00:00Added an answer on June 5, 2026 at 6:28 am

    You can use this awk 1 liner:

    awk '/gui : 789/{print NR}' file
    

    To process this inside a loop:

    while read l
    do
       echo $l
    done < <(awk '/gui : 789/{print NR}' file)
    

    EDIT: These command will work for any number of matches in the file. To store output of above line numbers in an array:

    arr=( $(awk '/gui : 789/{print NR}' x) )
    

    later on process these array elements as:

    echo ${arr[0]}
    echo ${arr[1]}
    ...
    echo ${arr[5]} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file containing a file dir.txt with the below data: /home/abc/a.txt /home/abc/b.txt
I have a string as below: $str = /dir1/dir2/dir3/file.txt I want to remove the
below is the code to download a txt file from internet approx 9000 lines
I have a file (called print_1012720.txt ) that looks like the text shown below.
Exact error: $ ./script.pl file.txt Can't open file.txt: No such file or directory at
I have written a perl code for processing file 'Output.txt' which has below Content.
I have a text file including the lines below: /* MY TXT File LINE
Below is sorted (on the basis of column one )tab delineated file named file.txt
I am using the code from proguard-android.txt file below # This is a configuration
I have a set of files in a directory like below: File-MyFile.txt File-AnotherFile.txt File-ThirdFile.txt

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.