grep -Evn "^$|#"

有时工作中需要把一些相关配置文件.conf 中的命令显示出来.如想查看mysql的my.cnf里的配置,可使用cat my.cnf  | grep -Evn "^$|#"
grep -E 扩展正归表达式
-v         排除
-n         打印行数
[root@mysql ~]# cat /etc/my.cnf  | grep -Evn "^$|#"
31:[client]
33:port         = 3306
34:socket               = /tmp/mysql.sock
42:[mysqld]
45:port         = 3306
46:socket               = /tmp/mysql.sock
48:basedir = /usr/local/mysql
49:datadir = /usr/local/mysql/var
51:init_connect='SET NAMES utf8'
52:skip-name-resolve
60:back_log = 50
76:max_connections      = 3000
86:max_connect_errors = 1000
93:table_cache = 2048
107:max_allowed_packet = 32M
117:binlog_cache_size = 1M
122:max_heap_table_size = 64M
128:sort_buffer_size = 8M
135:join_buffer_size = 8M
143:thread_cache_size = 8
150:thread_concurrency = 8
161:query_cache_size = 64M
166:query_cache_limit = 2M
172:ft_min_word_len = 4
182:default_table_type = MYISAM
189:thread_stack = 192K
193:transaction_isolation = REPEATABLE-READ
199:tmp_table_size = 64M
204:log-bin=mysql-bin
207:binlog_format=mixed
229:log_slow_queries
235:long_query_time = 2
240:log_long_format
259:server-id = 1
328:key_buffer_size = 32M
332:read_buffer_size = 2M
338:read_rnd_buffer_size = 16M
346:bulk_insert_buffer_size = 64M
352:myisam_sort_buffer_size = 128M
358:myisam_max_sort_file_size = 10G
364:myisam_max_extra_sort_file_size = 10G
369:myisam_repair_threads = 1
372:myisam_recover
387:innodb_additional_mem_pool_size = 16M
397:innodb_buffer_pool_size = 2G
405:innodb_data_file_path = ibdata1:10M:autoextend
414:innodb_file_io_threads = 4
424:innodb_thread_concurrency = 16
436:innodb_flush_log_at_trx_commit = 2
447:innodb_log_buffer_size = 8M
454:innodb_log_file_size = 256M
458:innodb_log_files_in_group = 3
469:innodb_max_dirty_pages_pct = 90
483:innodb_lock_wait_timeout = 120
486:[mysqldump]
489:quick
493:max_allowed_packet = 32M
494:[mysql]
495:no-auto-rehash
500:[isamchk]
501:key_buffer = 512M
502:sort_buffer_size = 512M
503:read_buffer = 8M
504:write_buffer = 8M
506:[myisamchk]
507:key_buffer = 512M
508:sort_buffer_size = 512M
509:read_buffer = 8M
510:write_buffer = 8M
512:[mysqlhotcopy]
513:interactive-timeout
515:[mysqld_safe]
521:open-files-limit = 10240