2

I have a very huge text file, and I want to know how can I find the first line in which the value of a variable is bigger than 1000?

Assuming that the variable and its value have only one space in between like this:

abcd 24
0

tail /dir/filename | grep " [1-9][0-9][0-9][0-9]"

This does not assume it is a 2 columns text file so might be a bit more versatile. If spaces behind the number just add a space in front of the last ".

Example:

rinzwind@discworld:~$ more test 
efweweff wqeddrwq 1 2 
ewfegf 1111
wfekn 22224
34jwefk 23  AAAASSSSS
12SQAs  q 21dqdwqw 2222   


rinzwind@discworld:~$ tail test  | grep " [1-9][0-9][0-9][0-9]"
ewfegf 1111
wfekn 22224
12SQAs  q 21dqdwqw 2222   

1111 2222 (not the 4 since it is checking on 4 digits only) and 2222 are highlighted red.

3
  • I forgot to say that the text file has composed of different lines with different formats. However, the "abcd" variable appears only in lines with the same format. BTW, the suggested command did not work. – user192995 Sep 15 '13 at 0:17
  • made a slight change and while at it added the example ;) – Rinzwind Sep 15 '13 at 0:21
  • naa my 1st post was flawed ;) – Rinzwind Sep 15 '13 at 0:22
3
awk '$1 == "abcd" && $2 > 1000 {print;exit}' yourfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.