LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2014, 02:49 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
how to remove extra spaces from | seperated file


Hi,

i have file test.txt with below format and it is containing lot of spaces after the last value of each row, how to remove that extra spaces in each row:
01072014|16:00|APPROVED|65027
01072014|16:04|DECLINED|1591
01072014|16:06|ADEPTRAOUTGOING|231
01072014|16:06|ADEPTRAINCOMING|1138
01072014|16:06|USERACCESSIBILITY|207
01072014|16:06|TRANSACTIONSFLOWING|65347

i tried below command:
sed -i '/^[ ]*$/d' test.txt
but it is not working
 
Old 07-03-2014, 03:21 AM   #2
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 535

Rep: Reputation: 79
You don't need to specify the starting of the line (^) if you want to remove only the tailling spaces.

The following will remove all spaces and tab characters at the end of each lines
Code:
sed -i 's/[ \t]*$//' test.txt

Last edited by angel115; 07-03-2014 at 03:23 AM.
 
2 members found this post helpful.
Old 07-07-2014, 11:56 PM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by angel115 View Post
You don't need to specify the starting of the line (^) if you want to remove only the tailling spaces.

The following will remove all spaces and tab characters at the end of each lines
Code:
sed -i 's/[ \t]*$//' test.txt
it is also helpful, Thanks a ton :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to remove extra spaces santosh0782 Linux - Newbie 18 01-27-2014 04:24 AM
[SOLVED] Remove spaces from a text file ceantuco Linux - Newbie 8 01-07-2014 03:22 PM
How to remove spaces from many file names under Cygwin gwc01 Linux - Newbie 4 11-22-2010 07:01 AM
[SOLVED] Remove extra spaces in a line vikas027 Programming 11 10-11-2008 09:20 AM
Need to remove spaces from all file / dir names ?? Solution here! jsjohnst Linux - General 2 07-20-2004 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration