Quantcast
Viewing all articles
Browse latest Browse all 13

Save AWK FNR as a Bash variable to continue search from the line

I’m trying to get to run this on a sorted file. This returns the last line which is less than or equal to the given value comparing the first 9 characters.

This would be done multiple times and VALUE would be assigned on each run and I have to continue the search from the line after which my previous solution has been found. I know FNR gives me the current line number but was not able to save it as a BASH variable for manipulation.

My file looks like this:

093051721DABCD
093052654EEFGH
093053087TIJKL

$ VALUE=093052054;
$ cat file | awk '{if((substr($0,0,9) <= $VALUE)){print $0} else exit}' | tail -1
093051721DABCD

Is there another way to do this?


Viewing all articles
Browse latest Browse all 13

Trending Articles