Remove Blank Spaces On Every Lines In Text Files

Suppose we have a text file like this :

tedy@tedy-laptop:~$ cat temp2
p16	p17	p18	p19	p20	p21	p22	p23 p24 p25
p26	p27	p28	p29	p30	p31	p32	p33	p34	p35
p36	p37	p38	p39	p40	p41	p42	p43	p44 p45
p46	p47	p48	p49	p50	p51	p52	p53	p54	p55
p56	p57	p58	p59	p60	p61	p62	p63 

tedy@tedy-laptop:~$

If we want to remove all blank space inside, we can do it by using the following command :

tedy@tedy-laptop:~$ cat temp2 | sed -e 's/[\t ]//g;/^$/d'
p16p17p18p19p20p21p22p23p24p25p26p27p28p29p30p31p32p33p34p35p36p37p38p39p40p41p42p43p44p45p46p47p48p49p50p51p52p53p54p55p56p57p58p59p60p61p62p63
tedy@tedy-laptop:~$

sed command is one of some power full text processing command in Shell environment.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.