If you have a text file with multiple lines running between each set of words or pharagraph, here's how to convert those multiple line breaks into single line breaks and totally remove paragraph lines, new lines or return lines inside text files.
Supposed you have a cluttered text file or configuration file with multiple line breaks or lines between set of words or paragraphs, you can easily remove them by using linux grep or tr command.
How to remove multiple empty lines, line breaks, new lines from a text file?
# cat testfile.txt
---------------------------------------------------------
1 1
ilovetux.com
2 2
3 3
4 4
---------------------------------------------------------
Blogspot may purged and blurred out the character space format from the above lines and remove new empty lines between the words, so here's a capture of the text file, see image shown below
To remove multiple lines or line breaks between each lines from text file using grep, simply
# cat testfile.txt | grep " "
# grep " " testfile.txt
Result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 1
ilovetux.com
2 2
3 3
4 4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now to suppress multiple lines or line breaks between each lines from text file using tr, simply
# cat testfile.txt | tr -s "\n"
would give you the same result that grep command had produced
Result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 1
ilovetux.com
2 2
3 3
4 4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enjoy.
Related Readings:
How To Delete and Remove New Lines from Text File
Strip and Remove Directory Name from Directory Path Name
Parse and Retrieve FileName Extension Only
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2008
(2301)
-
▼
January
(49)
- HowTo: Brasero
- HowTo: ISOs Management for Fedora
- HowTo: Install Nmap with GUI FrontEnd
- HowTo: Create and Manage Genealogy Family Tree via...
- HowTo: Install KFTPGrabber FTP Client
- HowTo: Install FileZilla 3 on Fedora 8
- HowTo: Be Alerted via Popups When Monitoring Log F...
- HowTo: Mount Windows Drive From Linux GUI
- HowTo: Delete Files With 0K Filesize Recursively
- HowTo: Changing Interface's MTU Size
- HowTo: Create Vanishing Virtual Drive
- HowTo: Install Identity.pub Into Remote Machines
- HowTo: Check and Mark Bad Block Of Hard Disk
- HowTo: Install Linux Hardware Browser
- HowTo: Basic RPM Package Queries And Usage
- HowTo: Rebuild Locked Out RPM Database
- HowTo: Display RPM Packages Installed Last Month
- HowTo: Display and List Out All Package Files Rece...
- HowTo: Identify Source Package Name Of A File or F...
- HowTo: Delete Extra Spaces Between Words From Files
- HowTo: Find Hidden Directory Folders Recursively
- HowTo: Create Hidden Directory Folder
- HowTo: Print Only Lines of Text File with N charac...
- HowTo: Sort Files by FileSize and What Else?
- HowTo: Squeezed Out Multiple Lines From Text File
- HowTo: Prevent Binary Execution From Mounted Device
- HowTo: Determine Domain's Expiration Date From Lin...
- HowTo: Create and Overwrite Existing Alias
- HowTo: Get MAC Address of PCs Around
- HowTo: List Out Hidden Files and Hidden Directory ...
- HowTo: Identify Valid Login Shells
- HowTo: Deny User from Logging Into Your System
- HowTo: Remove Tabs From Text Files Completely
- HowTo: Convert Tabs In Each File To Spaces
- HowTo: Install and Say Cheese
- HowTo: Install HomeBank and Manage Personal & ...
- HowTo: Install Mind-Mapping LabyRinth Tool
- HowTo: Install VMWare Server on Fedora 8
- HowTo: Install VMWare Workstation on Fedora 8
- HowTo: Virtual PCLinux 2007 via VirtualBox over Fe...
- HowTo: Enable PortMap on Fedora 8
- HowTo: Linux Hardware Lister Tool - LsHw
- HowTo: Install Bandwidth Shaper - Trickle on Fedora
- HowTo: VnStat Long-Term Traffic Monitoring via CLI
- HowTo: Install NetSpeed Traffic Monitoring Applet
- HowTo: Install IPTraff LAN Monitoring Tool
- HowTo: Install Ibmonitor Interface Bandwidth Monitor
- HowTo: Install IfTop Bandwidth Monitoring Tool
- HowTo: Fedora WordPress Installation
-
▼
January
(49)
Friday, January 18, 2008
HowTo: Squeezed Out Multiple Lines From Text File
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
0 comments:
Post a Comment