Hello @reach2khan, On forums we do encourage users to do add their efforts which they have put in order to solve their own problems. So please do add your efforts/attempts in form of code in your question and let us know then.
Wonder why that is? What's wrong with using a loop?
The subject of this thread is "Identify string field in csv ". How does your code achieve this "identification"?
How do you determine if a field contains ONLY alphabetic chars?
Does Mike 123 qualifies? Or Mike! ? Or anything with leading/trailing spaces (e.g.)?
Wonder why that is? What's wrong with using a loop?
Agree;we can go with the loop to identify if the field is a string - to make the code more generic.
How do you determine if a field contains ONLY alphabetic chars?
I am trying to check if 2nd and 5th field is alpha -numeric or not using [[:alpha:]]
Does Mike 123 qualifies? Or Mike! ? Or anything with leading/trailing spaces (e.g.)?
I am treating this field as alpha-numeric
What's the field separator in your sample?
it is comma - updated my command
What do you think "&&" is supposed to do?
I replaced with single & - the objective of adding "&" was to put the field that is read in quotes (as shown in the below cmd)
First of all your field 2 has a leading space ( Mike). Therefore your anchor (^) to the begining of the field fails to match.
Secondly, you're specifying the pattern to gsub incorrectly. It should be "^[[:alpha:]]+" - loose the slashes - they're taken literally inside the quotes. Or loose the quotes and leave the slashes - but not both.
So the code (the way you're implementing it) should look like:
In awk the better delimiters for a regex are the slashes. Well, you have to \/ escape an embedded / but there are less escapes necessary, compared to quote delimiters.
In gsub() the first argument is the regex, the 2nd is the substitution string, and strings are always delimited by quotes. (BTW the 3rd argument is a variable that is modified, if omitted it puts $0 i. e. the whole input line. )