Remove whitespace after pipe symbol but not inside words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove whitespace after pipe symbol but not inside words
# 1  
Old 04-19-2013
Remove whitespace after pipe symbol but not inside words

I have a file that looks like this:

Code:
102| #2 X 1/4-INCH|             30188|  EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #2 X 1/4-INCH
102| #2 X 1/4-INCH|             30188|  EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #2 X 1/4-INCH
102| #6 X 1/2"|                 06484|  EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #6 X 1/2"
102| #6 X 1/2"|                 06484|  EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #6 X 1/2"
102| #702-750SS12|              51506|  EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #702-750SS12
102| #702-750SS12|              51506|  EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  #702-750SS12
102| (TIPS) FXKD3151|           1DJ82|  EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  (TIPS) FXKD3151
102| (TIPS) FXKD3151|           1DJ82|  EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE|  (TIPS) FXKD3151
102| 00-000020|                 33ES4|  EA| FTW| A| NOT SERIAL TRACKING| LOT TRACKING|     TRUE|  00-000020

if I execute the cmd in VIM:

Code:
:%s/ \+//g

Code:
102|#2X1/4-INCH|30188|EA|FTW|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#2X1/4-INCH
102|#2X1/4-INCH|30188|EA|VPS|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#2X1/4-INCH
102|#6X1/2"|06484|EA|FTW|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#6X1/2"
102|#6X1/2"|06484|EA|VPS|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#6X1/2"
102|#702-750SS12|51506|EA|FTW|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#702-750SS12
102|#702-750SS12|51506|EA|VPS|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|#702-750SS12
102|(TIPS)FXKD3151|1DJ82|EA|FTW|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|(TIPS)FXKD3151
102|(TIPS)FXKD3151|1DJ82|EA|VPS|A|NOTSERIALTRACKING|NOTLOTTRACKING|TRUE|(TIPS)FXKD3151
102|00-000020|33ES4|EA|FTW|A|NOTSERIALTRACKING|LOTTRACKING|TRUE|00-000020

it will remove all whitespace after the | pipe symbol.

I tried to protect the pipe symbol but this command removed the pipe symbol and all whitespace

Code:
:%s/\| \+//g

What I want is to remove the whitespace only after the pipe symbol. But not the space between the part numbers themselves.
Like this:

Code:
102|#6 X 1/2"|06484|EA|FTW|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#6 X 1/2"
102|(TIPS) FXKD3151|1DJ82|EA|FTW|A|NOT SERIAL TRACKING NOT LOT TRACKING|TRUE|(TIPS) FXKD3151

How do I tell VIM to start with the | pipe symbol and remove the space up to the next word but not in the middle of words. I want to keep the space between (TIPS) FXKD3151 the part number for example.
# 2  
Old 04-19-2013
Code:
$ sed 's/| */|/g' file
102|#2 X 1/4-INCH|30188|EA|FTW|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#2 X 1/4-INCH
102|#2 X 1/4-INCH|30188|EA|VPS|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#2 X 1/4-INCH
102|#6 X 1/2"|06484|EA|FTW|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#6 X 1/2"
102|#6 X 1/2"|06484|EA|VPS|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#6 X 1/2"
102|#702-750SS12|51506|EA|FTW|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#702-750SS12
102|#702-750SS12|51506|EA|VPS|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|#702-750SS12
102|(TIPS) FXKD3151|1DJ82|EA|FTW|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|(TIPS) FXKD3151
102|(TIPS) FXKD3151|1DJ82|EA|VPS|A|NOT SERIAL TRACKING|NOT LOT TRACKING|TRUE|(TIPS) FXKD3151
102|00-000020|33ES4|EA|FTW|A|NOT SERIAL TRACKING|LOT TRACKING|TRUE|00-000020

# 3  
Old 04-19-2013
While in vim:

Code:
:%s/|\s*/|/g

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace the first and last character which is pipe symbol in all files within a folder?

with in my files i have the data like this, starting with a pipe and ending the line with a pipe. all i want is to replace the first and last pipe , remove those trying to use following sed command, but it is only showing on the screen the entire data of the file as if it removed, but when i... (4 Replies)
Discussion started by: cplusplus1
4 Replies

2. Shell Programming and Scripting

Remove pipe(|) symbol in except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (9 Replies)
Discussion started by: Sathyapts
9 Replies

3. Shell Programming and Scripting

Remove pipe(|) symbol ina file, except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (1 Reply)
Discussion started by: Sathyapts
1 Replies

4. Shell Programming and Scripting

Broken pipe symbol replaced with <A6><A6>

hi, i am copying an xml file from windows to linux server using filezilla&winscp. xml file contains ¦¦ symbols, after copying xml file to server ¦¦ is replaced with <A6><A6>. tried with copying xml files from windows in ascii&binary but no luck. please suggest. thanks (1 Reply)
Discussion started by: Satyak
1 Replies

5. Shell Programming and Scripting

Replace trailing whitespaces with pipe symbol using perl

I want to replace the whitespace with Pipe symbol to do a multiple pattern matching for the whole text "mysqld failed start" and same as for other text messages Below are the messages stored in a file seperate by whitespace mysqld failed start nfsd mount failed rpcbind failed to start for... (6 Replies)
Discussion started by: kar_333
6 Replies

6. Shell Programming and Scripting

Words after / symbol

Hi, I have the following directory: /home/dragon/websphere/cells/profile/imp/001/ I want to put this in a shell script and get the values before and after cells by removing the '/' Any idea how to make this possible? Regards, Dinesh (6 Replies)
Discussion started by: dbashyam
6 Replies

7. Shell Programming and Scripting

Problem while concating PIPE symbol with a file

Hi Gurus, I had a problem writing a pipe file. Previously i used this code to generate a tab seperated file ABCEF := ABCEF || 'to_char('|| abc_tab(col_num).col_name || ') chr(9) || '; Now i want the o/p as pipe seperated file.I changed the line as below ABCEF := ABCEF ||... (0 Replies)
Discussion started by: pssandeep
0 Replies

8. Shell Programming and Scripting

remove verticalbar or pipe symbol

hi guys i have 6000 rows column the text in the column has the symbol vertical bar |. i tried some of the commands to remove it but none of the commands are reconzng this symbol. would u plz help to remove this symbol from the text with any kind of unix command u r help would be appreciated ... (9 Replies)
Discussion started by: bogu0001
9 Replies

9. UNIX for Dummies Questions & Answers

remove whitespace

I combined 2 files using the paste command. It gave me something like this: 123445 ,AABBNN 22344 ,BBVVMM I want to remove the whitespace between the end of string 1 and the comma (there is more blank space than my post is showing). Would I... (2 Replies)
Discussion started by: nickg
2 Replies

10. Shell Programming and Scripting

remove whitespace and test

Hi, I know removing whitespaces I can found so many threads to read how it works and i did it, but my problem isn't solved... I have in my script a variable $1 which can contains a text like " Channel ". No I want to check if $1 contains the word Channel, but I don't know how many... (4 Replies)
Discussion started by: bensky
4 Replies
Login or Register to Ask a Question