hi ,
i am having one file which is having the contents like this :
"1111111111"
"2222222222"
"4444232344"
...
i want to check if all the patterns in the file follows this sequence like starting with " ending with " inside that 10 digits...
can anyone help me in checking that..
thanks,
Krips.
ynir
2
grep -E '^\"[[:digit:]]{10}\"$'
example:
# cat aaa | grep -E '^\"[[:digit:]]{10}\"$'
"1111111111"
"2222222222"
"4444232344"
# cat >bbb
"1111111111"
"2222222222"
"4444232d33"
"f666666666"
"6455"
# cat bbb | grep -E '^\"[[:digit:]]{10}\"$'
"1111111111"
"2222222222"
The following sed script will print out the line number and contents of any line that does not meet the pattern requirements.
#!/usr/bin/ksh
sed -n '/^"[0-9]\{10\}"$/!{=;p;}' file | \
sed '{
N;
s/\n/ /
}'
hi,
thanks a lot... it works perfectly..
@fpmurphy
can you please clear my doubt .. in that sed command what is !{=;p;} checking for..
Krips.
!{=;p;} means if a line does not match the regular expression i.e. exactly 10 digits, then print the line number followed by the line itself i.e.
10
FPM1234567
This output is then piped to a second invocation of sed which concatinates these 2 lines into a single line i.e.
10 FPM1234567