LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-13-2013, 01:55 PM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 584

Rep: Reputation: 37
Question Delete spaces from text file


Hi Guys,

I have a space delimited file that I would like to edit.

Basically, I need to delete 4 blank spaces.

See example:

Code:
 888 8888 888888888/ABC          88 888888888888888  1195.00
 888 8888 888888888/ABC          88 888888888888888      1195.00
I want to remove 4 spaces from the second line so it would match the first line. I tried using the CUT command but I could not do it.

Thank you

Last edited by colucix; 12-13-2013 at 03:07 PM. Reason: Added CODE tags to preserve spaces
 
Old 12-13-2013, 01:57 PM   #2
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 584

Original Poster
Rep: Reputation: 37
The forum fixed the margin for me... I should copy and paste the entire file here hehehhe well, the second line has 1195.00 moved 4 spaces to the right.

Thank you!
 
Old 12-13-2013, 01:58 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
If you want to show us the original formatting in your posts please use code-tags (look at the link in my signature) to post it.
 
Old 12-13-2013, 02:12 PM   #4
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 584

Original Poster
Rep: Reputation: 37
ok
Thank you!

[code]

800 8010 690041334/MOH 18 201015104280818 3195.00
800 8010 690041334/MOH 18 201015104280818 3195.00

Thank you
 
Old 12-13-2013, 02:14 PM   #5
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 584

Original Poster
Rep: Reputation: 37
Ok

Thank you

Code:

 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818      3195.00
 
Old 12-13-2013, 02:48 PM   #6
mddnix
Member
 
Registered: Mar 2013
Location: Bangalore, India
Distribution: Redhat, Arch, Ubuntu
Posts: 512

Rep: Reputation: 139Reputation: 139
Code:
$ cat file
 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818      3195.00
Code:
$ sed 's/8 *3/8  3/g' file
 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818  3195.00
Or, still better is
Code:
$ sed -e 's/^.//; s/  */ /g' file 
800 8010 690041334/MOH 18 201015104280818 3195.00
800 8010 690041334/MOH 18 201015104280818 3195.00

Last edited by mddnix; 12-13-2013 at 03:03 PM.
 
Old 12-13-2013, 03:53 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Using awk version 4:
Code:
awk 'NR == 1 {
  n = split($0, c, FS, s)
}
{
  for (i = 0; ++i <= n;)
    printf "%s", c[i] s[i]
  print ""
}' file
This preserves the spaces of the first line and print the other lines accordingly.
 
  


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] Unable to delete file - Text file busy Westmoreland Linux - General 3 10-16-2013 09:49 AM
Delete line of text from text file via shell? zizou86 Programming 3 01-13-2010 12:25 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 10:40 PM
Delete ^O from a text file pwc101 Programming 3 12-05-2007 12:02 PM
Delete the first row from a text file loopoo Linux - Newbie 2 08-15-2006 03:57 AM


All times are GMT -5. The time now is 10:31 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