Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find blank characters in a column

Status
Not open for further replies.

scottpeter

Programmer
Sep 23, 2003
28
US
I have a large data file which has fixed width data. How can I find out if there are any blank values in one of the columns. Or whether there are any blank characters in the value in the column.
Say for example the column length 10, it is the 5th column in the file and its position is 101-110.
Thanks,
Scott.
 
awk is your friend:
Code:
awk 'substr($0,101,10)~/ /{
  printf "NR=%d,Col5=/%s/\n",NR,substr($0,101,10)
}' /Path/To/YourInputFile

Hope This Help
PH.
 
Or using cut you could:


#Initialise a line counter to inform you of blank records
linecount=0
for field in `cut -c101-110`
do
$linecount=`expr linecount + 1`
if [ "x$field" == "x" ]; then
#This field is blank
echo "Record Number: $linecount, column 5 is blank"
fi
done

Forgive
 
How can I do the same, that is find the rows that have blank values in a particular column in a special character delimited file.

Thanks,
Scott
 
finding an lines in scott.txt (comma separated) where the third field is 'empty':
1,2,,4, 5, ,
1,2,3,4,5,6
1,2, ,4, 5,,

Code:
nawk -F, -v col=3 '$col ~ /^[ ]*$/' scott.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I am still not clear how to use it.
Suppose my data file has values like this with 'Ç' as delimiter, how will I check the values between these special characters.

Ç000002ÇCÇ702Ç869Ç
Ç000002ÇCÇ541Ç826Ç
Ç000002ÇCÇÇ994Ç
Ç000002ÇCÇ Ç532Ç
Ç000002ÇCÇ702Ç294Ç


Thanks,
Scott
 
for the THIRD empty field given your field separator:

nawk -F 'Ç' -v col=3 '$col ~ /^[ ]*$/' scott.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top