Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Sun Aug 20, 2017 4:49 am


Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

Author Message
LaR3
Post  Post subject: How to convert a text into a list of words, one per line  |  Posted: Wed Aug 05, 2009 7:02 am

Joined: Mon Aug 03, 2009 4:55 pm
Posts: 19

Offline
 

How to convert a text into a list of words, one per line

Depending on the type of processing you need to do on any file, it's possible you meight need to convert it into a list of words, with one word per line.

Code:
# cat test.file
FreeBSD 7.2-RELEASE is now available for the amd64, i386, ia64, pc98, powerpc, and sparc64 architectures.

FreeBSD 7.2 can be installed from bootable ISO images or over the network; the required files can be downloaded via FTP or BitTorrent as described in the sections below. While some of the smaller FTP mirrors may not carry all architectures, they will all generally contain the more common ones, such as i386 and amd64.


Turning test.file into a list of words with tr Unix utility is simple:
Code:
# cat test.file | tr ' ' '\n'
FreeBSD
7.2-RELEASE
is
now
available
for
the
amd64,
...


But this does not solve the problem with non-alpha characters.

This is how to transform the text contained in a file into a list of words removing non-alpha characters
Code:
# cat test.file| tr -cs "[:alpha:]" "\n"
FreeBSD
RELEASE
is
now
available
for
the
amd
...


This is how to transform the text contained in a file into a list of words removing only punctuation marks
Code:
# cat test.file | tr -d '[:punct:]' | tr ' ' '\n'
FreeBSD
72RELEASE
is
now
available
for
the
amd64
...


Post here your questions/opinions.

_________________
Humble user
http://www.ivorde.ro





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "How to convert a text into a list of words, one per line"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to convert pdf to text in FreeBSD

mandrei99

1

1086

Thu Jan 08, 2015 10:08 am

mandrei99 View the latest post

There are no new unread posts for this topic. Echo new line in linux - supress new line or echo multiple new lines

mandrei99

0

2788

Wed Jan 14, 2015 5:26 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to get the word frequency in a text

LaR3

0

2330

Wed Aug 05, 2009 7:01 am

LaR3 View the latest post

There are no new unread posts for this topic. SED uncomment line - How to uncomment a line or all lines with SED

mandrei99

0

3308

Wed Jan 14, 2015 5:08 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace new line in perl script

mandrei99

1

1813

Wed Jun 26, 2013 8:18 am

admin View the latest post

There are no new unread posts for this topic. grep match pattern: Binary file bincharacters.txt matches - How to make grep treat a file as text

mandrei99

0

642

Wed Dec 11, 2013 7:15 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to replace \w SED multiple matches on the same line without piping

mandrei99

0

1051

Tue Oct 08, 2013 6:29 am

mandrei99 View the latest post

There are no new unread posts for this topic. Removing new line / EoL characters in a PERL script

mandrei99

0

2332

Mon Nov 04, 2013 6:47 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to add line numbers in unix shell output

mandrei99

0

841

Fri Oct 31, 2014 5:31 am

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO