I want to find whether string values are available in a field of a file. Let it be any character other than number . I just want to know whether characters will be available in it . Please share a single step command for this without creating a shell script.
Please provide an example of representative input file, field, field separator, and by the way, what did you try so far ?
Would be helpful to know the definition of a "field".
A sample representative file/line would help as well....
Pipe delimter.Tried to get that specific field value
cut -d "|" -f 26 filename | head
From the above I found 10 values with all numbers . File is huge . With Grep I have to specify all characters But I don't that way .I just want a command to check whether characters are available in this field . Based on this I will decide it's datatype.
Please use code tags! (The co/de symbol at the top of the Wiki editor)
awk splits the input lines into fields $1 $2 ... $NF.
NF is number of fields, NR the line number.
awk -F "|" '{ print $26 } (NR==10) { exit }' filename'
You can add an egrep-like condition
awk -F "|" '($26 ~ /eregex/){ print $26 } (NR == 10) { exit }' filename'
And/or modify your output e.g. { print $0 }
that is the whole line.
if awk -F"|" '$COL ~ /[^0-9]/ { Z=1 } ; END { exit !Z }' COL=5 filename
then
echo "Character"
else
echo "Numeric"
then