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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove all lines lead with # signs (alone or with spaces/tabs before) 2

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

what would be universal solution to remove all lines like:

#sfsfs
# sfsfsf
# fsfsf
<TAB>#

 
could anyone pleae check and solution I created is ok?

Code:
$ echo "#\n\t #sfsfs\n#ssfsfsf       \n #sfdsfs\n#\n# sfdsdf\n     #dfdfds\n sfsfdfd sdfsfsf"
#
         #sfsfs
#ssfsfsf
 #sfdsfs
#
# sfdsdf
     #dfdfds
 sfsfdfd sdfsfsf
$ echo "#\n\t #sfsfs\n#ssfsfsf       \n #sfdsfs\n#\n# sfdsdf\n     #dfdfds\n sfsfdfd sdfsfsf"|awk '$1!~/^#/'
 sfsfdfd sdfsfsf
$
 
Hi

Yes, it is Ok.

Personally I usually avoid starting a script interpreter for such simple tasks. Generally [tt]grep[/tt] should be faster on such tasks. However this depends on the Awk/grep implementation too :
Code:
[blue]master #[/blue] time gawk '$1!~/^#/' w5000.txt > /dev/null
time 0m3.989s

[blue]master #[/blue] time mawk '$1!~/^#/' w5000.txt > /dev/null
time 0m2.427s

[blue]master #[/blue] time grep -v '^\s*#' w5000.txt > /dev/null
time 0m0.965s
Tested using [tt]gawk[/tt], [tt]mawk[/tt] and GNU [tt]grep[/tt] on your sample input*1?000?000.


Feherke.
 
A portable sed way:
Code:
sed '/^[ <Tab>]*#/d'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top