Removing spaces between parenthesis ()


Login or Register to Reply

 
Thread Tools Search this Thread
# 8  
Old 1 Week Ago
@RudiC: The link is broken.
This User Gave Thanks to stomp For This Post:
RudiC (1 Week Ago)
# 9  
Old 1 Week Ago
Thanks stomp! Fat fingers when copying the link. Corrected in above post...
# 10  
Old 1 Week Ago
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  
Old 1 Week Ago
Code:
sed  -e ':L' -e 's/\(([^ )]*\) \([^)]*)\)/\1\2 /; tL' file

# 12  
Old 1 Week Ago
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:
jim mcnamara (1 Week Ago)
# 13  
Old 1 Week Ago
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:
Neo (1 Week Ago)
# 14  
Old 1 Week Ago
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

More UNIX and Linux Forum Topics You Might Find Helpful
Removing blanks, spaces sususa Shell Programming and Scripting 5 07-03-2012 03:57 AM
Removing blank spaces rogerben Solaris 6 01-30-2012 02:30 AM
awk for removing spaces shruthidwh Shell Programming and Scripting 4 05-16-2011 12:25 PM
removing spaces in filenames ianebaj Shell Programming and Scripting 4 11-05-2010 02:32 AM
Removing spaces from record raghavendra.cse Shell Programming and Scripting 3 04-08-2010 07:27 AM
Removing spaces within Filename Fishn Shell Programming and Scripting 7 10-21-2009 12:21 PM
Removing spaces in a line krishna_gnv Shell Programming and Scripting 2 09-20-2009 10:20 PM
Removing blank spaces, tab spaces from file NARESH1302 Shell Programming and Scripting 3 08-07-2009 11:18 AM
Removing spaces from string ippy98 Shell Programming and Scripting 7 03-18-2009 11:10 PM
Removing spaces from data monika Shell Programming and Scripting 4 11-09-2008 03:34 PM
Removing spaces... lost UNIX for Dummies Questions & Answers 2 10-06-2008 05:46 PM
removing spaces sahithi_khushi Shell Programming and Scripting 2 11-03-2006 10:20 AM
Removing spaces at particular position superprogrammer Shell Programming and Scripting 7 07-10-2006 05:29 AM
removing spaces after sperator vishnu_vaka Shell Programming and Scripting 6 03-24-2006 09:17 AM
Removing spaces between records thanuman UNIX for Dummies Questions & Answers 6 11-17-2005 12:01 PM