Posts tagged sed

Count bytes and characters with wc

Count bytes and characters with wc

wc -c filename == counts the bytes
wc -m filename == counts the characters

this can be combined with other commands like grep, awk, sed

example with sed:

sed -n '1p' filename | wc -c

the above will print the first line from filename and count the bytes in that line

sed tricks to replace multi blank spaces and tabs with single space

Replace all multi-blankspaces (more than one spaces/tabs) in file with mono-blankspace (one space):

sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename

can also be:

 sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename > newfilename

note: g in the end means GLOBAL

In the above samples, <space> means ‘ ‘ (empty space) and <tab> means ‘      ‘ (tab key press).

Go to Top