Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Removing spaces between parenthesis ()


Login or Register to Reply

 
Thread Tools Search this Thread
# 8  
@RudiC: The link is broken.
This User Gave Thanks to stomp For This Post:
# 9  
Thanks stomp! Fat fingers when copying the link. Corrected in above post...
# 10  
Thank you all for your inputs!

Looking at little bit at Perl one-liner did the trick

Code:
perl -pe 's{(\([^\)]*\))}{($r=$1)=~s/ //g;$r}ge' test.txt

# 11  
Code:
sed  -e ':L' -e 's/\(([^ )]*\) \([^)]*)\)/\1\2 /; tL' file

# 12  
Quote:
Originally Posted by nms
Hi,

Thanks for your responses. Unfortunately, none of these worked. Forgot also to tell that the platform is Solaris 10 i86.

Code:
[PRODUCTION] root@das:/var/opt/Aspider-NGI/nms/output> awk -F'[)(]' '{for(i=2; i<=NF; i+=2) {p=$i; gsub(/ /,x,p); sub($i,p)}}1' test.txt
awk: syntax error near line 1
awk: illegal statement near line 1
[..]

Like RudiC mentioned, on Solaris, use /usr/xpg4/bin/awk, not regular awk ...
This User Gave Thanks to Scrutinizer For This Post:
# 13  
The following code works:

Code:
#!/bin/sh

# POSIX shell compliant.

grep -i "httpd" input.txt | sed "s/ //" | sed "s/ //" |sed "s/(/ (/"

exit 0

This User Gave Thanks to johnprogrammer For This Post:
# 14  
Quote:
Originally Posted by johnprogrammer
The following code works:

Code:
#!/bin/sh

# POSIX shell compliant.

grep -i "httpd" input.txt | sed "s/ //" | sed "s/ //" |sed "s/(/ (/"

exit 0

Hi johnprogrammer,
Welcome to the UNIX and Linux forums.

Note that the problem being addressed in this thread didn't say anything about only wanting to remove spaces between parentheses on lines that also contain the string "httpd".

Note that the problem being addressed in this thread didn't say anything about removing lines that do not contain spaces between parentheses.

Note that the problem being addressed in this thread didn't say anything about only wanting to remove a single space between parentheses.

Note that the problem being addressed in this thread didn't say anything about only wanting to remove spaces between parentheses only lines that have exactly one <space> before the first parenthesis on that line.

Note that in post #1 in this thread, the desired sample output for the line that is to be changed also deletes a bunch of spaces and a number after the parentheses (which wasn't mentioned in the English description of the problem).

Please be careful about saying that your code works when it looks like the code that you have provided makes several assumptions that do not seem to match the requirements being addressed in this thread.

Hi nms,
I would also like to welcome you to the UNIX and Linux forums.

Please don't just say "Unfortunately, none of these worked."; please tell us where they fell short of doing what you wanted.

The requirements you stated in post #1 in this thread didn't make it clear whether or not lines that did not have a <space> between parentheses were supposed to be included in the output you are trying to produce or not.

The requirements you stated in post #1 in this thread didn't say anything about removing the <space>s and the "0" at the end of the line from the line you did want to change, but the sample output you provided removed those character as well as the <space> that was on that line between the parentheses.

In the future, please try to give a more complete description of exactly what it is that you are trying to do.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing blanks, spaces

I have pipe separated file with lots of blank spaces. After using sed -e 's/ *| */|/g' this command ,its giving me output as TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL ... (5 Replies)
Discussion started by: sususa
5 Replies

2. Shell Programming and Scripting

removing spaces in filenames

I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command? find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies

3. Shell Programming and Scripting

Removing spaces from record

HI i have record as shown below 402665,4X75,754X_FERNIE BC,12F2,008708,FERNIE BC,1,UTC ,UTC ,250 402665,4X75,754X_FERNIE BC,F212,008708,FERNIE BC,1,UTC ,UTC ,250 402665,4Y75,754Y_FERNIE BC,22F2,008708,FERNIE BC,1,UTC ,UTC ,250 here i want to remove multiple spaces into no... (3 Replies)
Discussion started by: raghavendra.cse
3 Replies

4. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

5. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

6. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

7. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

8. Shell Programming and Scripting

removing spaces after sperator

Hi friends i have problem 6000000001| CDC049| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000002| CDC033| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000003| CDC037| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000004| CDC031| ... (6 Replies)
Discussion started by: vishnu_vaka
6 Replies

9. UNIX for Dummies Questions & Answers

removing spaces from variables?

I stored results like this VAR=`wc -l < ls.txt` But the value of the wc gave me a padded number. How do I strip the padding from $VAR? Do you think I could use SED? Except instead of a file input, have a variable redirection input? (2 Replies)
Discussion started by: yongho
2 Replies

10. Shell Programming and Scripting

removing spaces in a file

I have output a file and need to remove blank spaces in the first lines only so the file is left end justified. I need to do this while keeping the rest of the file intact. Example of file that needs spaces removed: space space space space space space space... (3 Replies)
Discussion started by: tioray
3 Replies

Featured Tech Videos