I am looking for a solution to display those lines in any file that contains 80 or more characters along with their corresponding line number in the file.
The below script will print the lines with their corresponding line numbers...
sed = Sample.cpp | sed 'N;s/\n/\t/; s/*\(.\{6,\}\)\n/\1/' | sed -n '/^
.\{80\}/p'
but i've found that the sed command for numbering has affected the final result......the new result calculates the line numbers as characters too.....which i dont require......
Does any one have any alternate idea to get the expected result ???? Kindly help......
I tried the mentioned methods..but its partially working....but again some interesting results. I am using vi to edit the code...and i entered "ii" 4 times by adding tab space in between such that the last "ii" will be place after 79..like given below...
(well the space between "ii"'s is bit large say 8 tab space, the unix forum text editor is not allowing me to demonstrate that.....)
ii ii ii ii
If i use the following script
egrep -n '.{80}' VerCsm.cpp
it does not print the exceeded line....ii
but the interesting fact is that..if i type
iiiiiii...........
continuous till 80 or more....with no tab space in between the above script will work......dont know why ???? any idea ?????......for time being i assume that the cases i face will be the second one....and will continue to use the mentioned scripts.......thnks..
Like mentioned above, you will need to expand tabs. A tab character is a single character but uses the width of up to 8 characters. You can calculate the actual width of each tab yourself, but it's probably easier if you pipe the file through expand
Neither of those example lines have a display width of over 79 characters. Anyway, again: a tab is a single character and the script counts characters. If you want to work on the display width, you will need to expand tabs one way or another.
Did you try the expand command as suggested above?
expand <<HERE | egrep -n '.{80}'
# eleven tabs with ii in between them
ii ii ii ii ii ii ii ii ii ii ii ii
disregard this short line
# six spaces eleven times, with ii in between
ii ii ii ii ii ii ii ii ii ii ii ii
HERE