sed - What is regular expression for first field containing alpha-numeric? -


i have data starts out in .csv file

"684mf7","684mf7","rn"

the first field "684mf7" should contain numeric characters; no alpha characters should present in first field. have other checks second field, in case "684mf7", legitimate value second field.

i want find alpha in first field, , print line. invoke sed file

{         /^".*[^0-9]*.*",/p } 

with -n , -f (for file name).

what regular expression isolates first field only? getting match on everything, isn't want. problem because trying match 0 or more instead of 1 or more alpha characters?

the first field (any content) selected by:

/^"[^"]*"/ 

you want @ least 1 of characters in field alpha (though might better regarded 'non-digit'), in case 1 of these should select you're after:

/^"[^"]*[a-za-z][^"]*"/ /^"[^"]*[^0-9"][^"]*"/ /^"[^"]*[[:alpha:]][^"]*"/ /^"[^"]*[^"[:digit:]][^"]*"/ 

note negated classes must not match double quote either (one reason testing answers — first version of script below listed both lines of input).

and converting 1 of sed command:

sed -n '/^"[^"]*[^"[:digit:]][^"]*"/p' <<eof "684mf7","684mf7","rn" "684007","684mf7","rn" eof 

another way of looking @ problem "print line first field not digits (with @ least 1 digit present)". is:

sed -n '/^"[[:digit:]]\{1,\}"/!p' <<eof "684mf7","684mf7","rn" "684007","684mf7","rn" eof 

on whole, perhaps better solution use (and shan't complain if use [0-9] in place of [[:digit:]]).


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -