find sequence of 13 digits in file

I need to extract all sequences of thirteen digits in a file, e.g. 4384976350232, and at the same time not extract sequences with 14 or more digits.

How do I do that using sed, awk or something built into bash?

How does your input file look like? how are the fields separated?

--ahamed

the 13 digit sequences are separated by "}" , "{" , ":" or ","

Paste a sample input!...

--ahamed

---------- Post updated at 04:46 AM ---------- Previous update was at 04:37 AM ----------

Try this...

awk -F"[{}:,]" '{for(i=1;i<=NF;i++){if($i ~ "^[0-9]" && length($i)==13){print $i}}}' input_file

--ahamed

1 Like

I will try

Try the code in the previous post and let me know if it works for you...

--ahamed

1 Like

thanks, that actually works!

Hi.

If your grep supports it:

$ grep -o '\b[0-9]\{13\}\b' file1
1323599800213
1323599800727
awk -F"[{}:,]" '{for(i=1;i<=NF;i++){if($i==int($i) && length($i)==13){print $i}}}' file

To be more precise :wink: