[Solved] Howto remove extra space in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Howto remove extra space in the file
# 1  
Old 06-04-2013
[Solved] Howto remove extra space in the file

Hi Gurus,

I have a file which contains some special char or space.
when using cat -evt I can see the file as following:

Code:
0,"0000","abc/def aaa                                                                                                                              ","01/01/1900","12/31/2299",1001,"abc"$
1,"0001","abc > 1cde                                                                                               ","01/01/1900","06/30/2013",1001,"abc"$


Code:
0,"0000","abc/def aaa ","01/01/1900","12/31/2299",1001,"abc"$

should be in one line,but it appears as two lines without any line feeder. the strange thing is I copied this from vi editor, I can not move it to one line using backspace key.

anybody has some idea how to remove these extra space in unix.
after posting I found the file became one line with big space. when I copied it from vi editor to notepad, it appears as two line.

I print a screeshot, but I dont know how to attached it, can anybody tell me how can i attach a screenshot.



Thanks in advance.

Last edited by ken6503; 06-04-2013 at 01:24 PM..
# 2  
Old 06-04-2013
Well, it's already in one line, isn't it? Or am I missing something?

From your pasted input it definitely seems that there are several blank characters in the third field.

The line may be so wide that it's not fitting your screen and it apparently breaks into two lines, even though it's only one.
# 3  
Old 06-04-2013
Using awk
Code:
awk '{$1=$1}1' file

These 3 Users Gave Thanks to Yoda For This Post:
# 4  
Old 06-04-2013
Quote:
Originally Posted by Yoda
Using awk
Code:
awk '{$1=$1}1' file

very clever Smilie
# 5  
Old 06-04-2013
Quote:
Originally Posted by Yoda
Using awk
Code:
awk '{$1=$1}1' file

This works perfectly, would you please briefly explain this for me since I don't have that much unix experience.

Thanks
# 6  
Old 06-04-2013
This is a very commonly used solution. It reconstruct every field setting default one space as filed separator.
{$1=$1} reconstruct
1 print every line
This User Gave Thanks to Jotne For This Post:
# 7  
Old 06-04-2013
Quote:
Originally Posted by Jotne
This is a very commonly used solution. It reconstruct every field setting default one space as filed separator.
{$1=$1} reconstruct
1 print every line
Thanks for your explanation.

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extra Space in output - remove

Hi All I am trying to perform the below operation -count=`cat abc.txt | wc -l` echo$count 5 Head=Start"$DATE"00000"$count"File echo $HEAD START15020300000 5File There is a space coming before 5 which is not needed . How to ignore that . (4 Replies)
Discussion started by: honey26
4 Replies

2. UNIX Desktop Questions & Answers

To remove the extra spaces at the end of each line in a file

I have a file of about 10k records and eace line is having an extra space of 5 byte at the end.. Iwant to remove the extra spaces at the end of each line.. Can someone please help me out.. I tried using sed command and its not working... can someone please help me out. (3 Replies)
Discussion started by: rammohan
3 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Help to remove a line from a file

Hi, I just upgraded one my server to latest version RHEL, I have many users who will do SSH from another server. I wanted to update all of the users home directory and remove the security key. For example. /home/XYZ/.ssh/known_hosts and remove this hostsname. Please see below and advise.... (2 Replies)
Discussion started by: samnyc
2 Replies

4. Shell Programming and Scripting

[Solved] remove file extension

Hi, I have some files with some extension e.g. abc.xml.REMOVE,xyz.xml,efg.xml.REMOVE . I have to remove the .REMOVE extension. I can display it using the below script but cannot rename it. ls -l|sed 's/\.REMOVE//' How can I rename this? Thanks in advance (7 Replies)
Discussion started by: babom
7 Replies

5. UNIX for Advanced & Expert Users

howto remove meta info about MP4 or FLV file downloaded off Youtube?

Hi I tried a tool called mediainfo > brew info media-info media-info 0.7.51 http://mediainfo.sourceforge.net Depends on: pkg-config /usr/local/Cellar/media-info/0.7.51 (3 files, 14M) http://github.com/mxcl/homebrew/commits/master/Library/Formula/media-info.rb Got details from a test... (3 Replies)
Discussion started by: slashdotweenie
3 Replies

6. Shell Programming and Scripting

How to remove extra double quotes from string in a delimited file??

Hi Unix Gurus.. I am new to Unix. Please help me. The file I am getting is as follows: Input File "2011-07-06 03:53:23","0","I","NOT SET ",,,,"123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N" "2011-07-06 03:53:23","0","I","NOT SET ",,,,"204312","ARMAFLEX-1 3/8 X... (2 Replies)
Discussion started by: BICC
2 Replies

7. Shell Programming and Scripting

shell script to remove extra commas from CSV outp file

Name,,,,,,,,,,,,,,,,,,,,Domain,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Contact,Phone,Email,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Location -----------------------,------------------------------------------------,-------,-----,---------------------------------,------------------------------------ ----... (1 Reply)
Discussion started by: sreenath1037
1 Replies

8. Shell Programming and Scripting

m4 adds extra space at top of file.

I have used m4 in the past to generate source code where aesthetics and space were of no consequence . Now I am using it to generate script and program templates . So here is an excerpt from my m4 file for producing a generic bash script: dnl `$Id$' define(`START_SCRIPT',`#!/bin/bash... (8 Replies)
Discussion started by: Bubnoff
8 Replies

9. HP-UX

[Solved] Howto change subdirectory easily using cd

Hi all, how to change the path easily from /u01/oracle/oradata/newdb/tab >cd olddb /u01/oracle/oradata/olddb/tab > or /u01/oracle/oradata/newdb/tab >cd u05 /u05/oracle/oradata/newdb/tab > I am lazy for typing the abs. path again... As I know there is some "tips" in doing this. ... (2 Replies)
Discussion started by: freddy1228
2 Replies

10. Shell Programming and Scripting

remove extra lines in the file

Hi, I have some files, with some extra lines in weird characters on the top and bottom of the. I want to get rid of those line. Is there a way I can do that? example of the input file. I want to get rid of those lines in bold  ... (8 Replies)
Discussion started by: CamTu
8 Replies
Login or Register to Ask a Question