Print limited characters per a line
Printing first 80 characters in a line.Below are the different ways to do it.Cut
cut -c1-80 your_fileAwk
awk '{print substr($0,0,80)}' your_file
Sedsed -e 's/^\(.\{80\}\).*/\1/' your_file
Perlperl -lne 'print substr($_,0,80)' your_file
perl -lpe 's/.{80}\K.*//s' your_file
Grep
grep -o "^.\{80\}" your_file
.png)







I am a software programmer working in India. I usually like to blog in my free time.
That's all fine and dandy, but I once attempted to write a script to do the same thing (wrap the text, splitting using whitespace, independent of terminal width... basically a fold command). That's a piece of cake...
ReplyDeleteThe catch? I want to do the same thing but with text containing control characters and hidden terminal formatting codes, escape characters (are those part of control? dunno), etc.
The script turned out to be a nightmare to write. I finally got one working but it's useless because it's WAY too slow. Too many calculations...
Care to tackle the topic?
— Yuri
That's worth a thought. Surely will try it out some time.
ReplyDelete