Need shell script for following problem.

October 4, 2010 at 05:52:43
Specs: Windows XP
Hi ,
My problem is to find out how many ~"tildas" present in each row, also check if number of tildas"~" are not same as declared in variable then it shoul give an error. also it should scan whol file and show in which line the tildas are not same. That means each row should contains same number of tildas"~".
One more thing i need to read the constants from another propety file. for example.
file has

count.txt has data
this script should scan whol count.txt file and check if row 1=14 tildas if yes then check next if not then it should gives an error like line number 1 dont have 14 tildas, agin it should go ahead and check 2nd row if tildas are 14 hen next and so on......
Also it should scan so fast. i will be having around more than 50 thousands of records. so it shoul not take more than 1 or 2 mins

Thanks & Regards,

See More: Need shell script for following problem.

October 6, 2010 at 07:28:43
declare the tilde as a field separator for awk and count the number of field.
that number -1 is the amount of tilde characters per record
sth like:
cat inputfile | awk 'BEGIN {FS = "~"} {if ( NF-1 != 14 ) print $0 }' > outputfile

outputfile will contain all records with not exactly 14 tilde characters


Report •

October 19, 2010 at 17:54:23
>>cat inputfile | awk 'BEGIN {FS = "~"} {if ( NF-1 != 14 ) print $0 }' > outputfile

lose the cat. Its useless and takes up 1 process...pass the file directly to awk.

GNU win32 packages | Gawk

Report •
Related Solutions

Ask Question