Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
94 views
in Technique[技术] by (71.8m points)

How to fetch a number ending with a specific digit in linux

I have a file somewhat like :
Hello, World!
Name Age Place
Abc 26 CO
Def 27 CA
Ghi 45 MH
Jkl 32 SD

How to find the line in which Age ends with 2?
Output I am expecting is - Jkl 32 SD

question from:https://stackoverflow.com/questions/65915621/how-to-fetch-a-number-ending-with-a-specific-digit-in-linux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should be able to do this with GREP utility, using the -n option, which will prefix each line of output with the line number of the input file.

If this is your input file:

Hello, World!
Name Age Place
Abc 26 CO
Def 27 CA
Ghi 45 MH
Jkl 32 SD

Then:

$ grep -n "2 " inputFile.text
6: Jkl 32 SD

Here you can see that the pattern you are looking for can be found on line 6.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...