Sponsored Content
Top Forums Shell Programming and Scripting Replacing Multiple spaces with a single space but excluding few regular expressions Post 302957158 by sparks on Wednesday 7th of October 2015 04:49:20 PM
Old 10-07-2015
Replacing Multiple spaces with a single space but excluding few regular expressions

Hi All.

Attached are two files.

I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt "
I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line.

But in two columns I.e., the second and third column, I have a description where it has spaces in between and it should NOT be removed. But as I apply a 'tr' on the whole file, even those spaces are removed.

Could you please help me, how to retain the spaces in that string and replace everything else.

Below is how it looks after removing spaces:

Code:
 
657715,"SvcLoc,20458,IP,Normal,N/A","SvcSeg,88FT,0.5IN,PL,DNA"
655873,"SvcLoc,24558,IP,Normal,N/A,C","SvcSeg,46FT,1IN,PL,DNA"

It should look like this:

Code:
657715,"Svc Loc , 20458, IP, Normal, N/A","Svc Seg, 88FT, 0.5IN, PL, DNA"
655873,"Svc Loc ,24558 ,IP ,Normal ,N/A ,C","SvcSeg,46FT,1IN,PL,DNA"

Any suggestion will be very helpful. Please let me know if my question is not clear!

Thank You!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing single space in argument

I want to write a script which will check the arguments and if there is a single space(if 2 more more space in a row , then do not touch), replace it with _ and then gather the argument so, program will be ran ./programname hi hello hi usa now hello hello so, inside of program,... (7 Replies)
Discussion started by: convenientstore
7 Replies

2. Shell Programming and Scripting

Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"): e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA When I read this record and either echo/print to screen or write to... (4 Replies)
Discussion started by: NinersFan
4 Replies

3. Shell Programming and Scripting

replace space or spaces in a line of a file with a single :

I am searching while I await a response to this so if it has been asked already I apologize. I have a file with lines in it that look like: bob johnson email@email.org I need it to look like: bob:johnson:email@email.org I am trying to use sed like this: sed -e 's/ /:/g' file >... (5 Replies)
Discussion started by: NewSolarisAdmin
5 Replies

4. UNIX for Dummies Questions & Answers

Regular Expressions -- Find spaces outside

Hello, I need help with using grep and regular expressions.... I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt: 意文 yìwén (given name) 貴姓 guìxìng (honorable surname) 貴 guì (honorable) 姓 xìng (one's surname is; to be surnamed; surname) 呢 ne (interrogative... (2 Replies)
Discussion started by: arduino411
2 Replies

5. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

6. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

7. UNIX for Dummies Questions & Answers

How to translate multiple spaces into a single space using tr command?

I am trying to read a txt file and trying to translate multiples spaces into single spaces so the file is more organized, but whenever I try the command: tr ' ' ' ' w.txt The output is: tr: extra operand `w.txt' Try `tr --help' for more information. Can someone please help? :wall: ... (2 Replies)
Discussion started by: Nonito84
2 Replies

8. Shell Programming and Scripting

Replacing trailing space with single quote

Platform : RHEL 5.8 I want to end each line of this file with a single quote. $ cat hello.txt blueskies minnie mickey gravity snoopyAt VI editor's command mode, I have used the following command to replace the last character with a single quote. ~ ~ ~ :%s/$/'/gNow, the lines in the... (10 Replies)
Discussion started by: John K
10 Replies

9. UNIX for Dummies Questions & Answers

Replacing double spaces with single space

I am looking for a regular expression that uses sed to replace multiple spaces with single spaces on every line where it is not at the start of the line and not immediately before double slashes ('//') or between quotes ("). In its simplest form, it would look like this: sed -e 's# # #g'... (4 Replies)
Discussion started by: figaro
4 Replies

10. Shell Programming and Scripting

BASH - Regular Expressions :Looking for one word on multiple lines.

Im looking for a bash solution that will use Regular Expressions (not perl, sed or awk) to check the example data below and then give me a status. which would be just simply Match or Mismatch. SYS PS1 is present. Fan status: Normal Input Voltage status: Normal ... (5 Replies)
Discussion started by: popeye
5 Replies
GLAM2-PURGE(1)							   glam2 Manual 						    GLAM2-PURGE(1)

NAME
glam2-purge - Removes redundant sequences from a FASTA file SYNOPSIS
glam2-purge file score [options] DESCRIPTION
glam2-purge is a modified version of Andrew Neuwald's purge program that removes redundant sequences from a FASTA file. This is recommended in order to prevent highly similar sequences distorting the search for motifs. Purge works with either DNA or protein sequences and creates an output file such that no two sequences have a (gapless) local alignment score greater than a threshold specified by the user. The output file is named <file>.<score>. The alignment score is based on the BLOSUM62 matrix for proteins, and on a +5/-1 scoring scheme for DNA. Purge can also be used to mask tandem repeats. It uses the XNU program for this purpose. OPTIONS
-n Sequences are DNA (default: protein). -b Use blast heuristic method (default for protein). -e Use an exhaustive method (default for DNA). -q Keep first sequence in the set. -x Use xnu to mask protein tandem repeats. SEE ALSO
glam2(1), glam2format(1), glam2mask(1), glam2scan(1), xnu(1) The full Hypertext documentation of GLAM2 is available online at http://bioinformatics.org.au/glam2/ or on this computer in /usr/share/doc/glam2/. REFERENCES
Purge was written by Andy Neuwald and is described in more detail in Neuwald et al., "Gibbs motif sampling: detection of bacterial outer membrane protein repeats", Protein Science, 4:1618-1632, 1995. Please cite it if you use Purge. If you use GLAM2, please cite: MC Frith, NFW Saunders, B Kobe, TL Bailey (2008) Discovering sequence motifs with arbitrary insertions and deletions, PLoS Computational Biology (in press). AUTHORS
Andrew Neuwald Author of purge, renamed glam2-purge in Debian. Martin Frith Modified purge to be ANSI standard C and improved the user interface. Timothy Bailey Modified purge to be ANSI standard C and improved the user interface. Charles Plessy <plessy@debian.org> Formatted this manpage in DocBook XML for the Debian distribution. COPYRIGHT
The source code and the documentation of Purge and GLAM2 are released in the public domain. GLAM2 1056 05/19/2008 GLAM2-PURGE(1)
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy