Showing posts with label linux command tr replace blanks. Show all posts
Showing posts with label linux command tr replace blanks. Show all posts

Sunday, March 15, 2015

Replace Consecutive Blanks With a Single Blank (Continued)

In an earlier post Replace Consecutive Blanks With a Single Blank, we use SQL regexp_replace() to replace consecutive blanks with a single blank. We may also use Linux command tr to do the same before we load a text file into a database.

$ cat x.txt
hello    world!
This   is a  test .
Using "tr -s ' '" command to squeeze consecutive blanks into one.
$ cat x.txt | tr -s ' '
hello world!
This is a test .
Many Linux/Unix commands are very useful to clean up text files. I am using Windows but I installed open source Cygwin that provides a Linux environment. In another example Calculate Histogram for a Text File, we calculate the histogram using Linux commands.