Re: Ignoring comments and blank lines in a data file
- From: Dave B <daveb@xxxxxxxxxxxx>
- Date: Thu, 17 Jul 2008 13:44:07 +0200
Mark Hobley wrote:
I have a set of data files containing a list of network addresses and
blank lines as follows:
[snip]
What is the simplest way to cut out the hash symbols and any text
beyond? I am thinking of using some sort of arrangement using cut as
follows:
cut -f 1 -d '#'
This would strip the comments, but I need to also get rid of blank lines
and spaces.
You can filter the input through sed:
sed -n 's/#.*//;/^[[:space:]]*$/!p' file | while IFS= read -r netaddr; do ....
Note that your IP addresses use different formats, ie some have the /nn
(prefix length) and some don't.
--
echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#;
s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b;
s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/;
tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
.
- Follow-Ups:
- Re: Ignoring comments and blank lines in a data file
- From: Dave B
- Re: Ignoring comments and blank lines in a data file
- References:
- Ignoring comments and blank lines in a data file
- From: Mark Hobley
- Ignoring comments and blank lines in a data file
- Prev by Date: Re: Ignoring comments and blank lines in a data file
- Next by Date: Re: Ignoring comments and blank lines in a data file
- Previous by thread: Re: Ignoring comments and blank lines in a data file
- Next by thread: Re: Ignoring comments and blank lines in a data file
- Index(es):
Relevant Pages
|