remove space between the operator, script required...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove space between the operator, script required...
# 1  
Old 06-17-2009
remove space between the operator, script required...

Hi...

i need a script to remove the space before and after the operator like( +, -, ||, &&).

Ex :

Input file

apple + manago

mango && fresh + apple fresh || fruit


Desired output:

apple+manago

mango&&fresh+apple fresh||fruit


Note: betwee the desired operator space should be removed, between words do not remove space.

Thanks in advance,
Vasanth
# 2  
Old 06-17-2009
Try to build something like this...
Code:
echo "mango && fresh + apple fresh || fruit" | sed 's/\(.*\)\( && \)\(.*\)\( + \)\(.*\)\( || \)\(.*
\)/\1\&\&\3+\5||\7/'

# 3  
Old 06-17-2009
Dear rakeshawasthi ,

i have a big file containing different names, and the operators(+,&&. -. ||) not in the a proper order. Kindly concern about the spaces near to the operators only.

And input is a file....

Thanks in advance...
Vasanth

Bump: Thanks in advance
vasanth

Bump: Thanks in advance
vasanth
# 4  
Old 06-17-2009
Code:
sed -e 's/[ ]*+[ ]*/+/g' -e 's/[ ]*||[ ]*/||/g' -e 's/[ ]*\&\&[ ]*/\&\&/g' -e 's/[ ]*-[ ]*/-/g' input_file.txt

# 5  
Old 06-17-2009
Thanks..

Dear Panyam,

Thanks. well done....Smilie

Thanks a lot,
Vasanth
# 6  
Old 06-17-2009
Ohh, I think my hint was good enuf for you to start with...anyways,
Code:
cat inputfile | sed 's/[ ]+[ ]/+/g' | sed 's/[ ]||[ ]/||/g' | sed 's/[ ]&&[ ]/\&\&/g'

# 7  
Old 06-17-2009
Thanks....

Thanks rakeshawasthi,

urs too working fine..

ThanksSmilie
vasanth

-----Post Update-----

Dear panyam / rakeshawasthi ,

In the above case everything fine, but if i want to remove the spaces before and after / operator, what i need to do add in sed...

-----Post Update-----

Dear panyam / rakeshawasthi ,

In the above case everything fine, but if i want to remove the spaces before and after / operator, what i need to do add in sed...

-----Post Update-----

Thanks in advance
vasanth

-----Post Update-----

Advance thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Required paging space recommandations on AIX5.3

Hi Guys, Can some one help me on what is the recommended (SWAP) Paging space required. Below are the details of my environment Currently The OS version AIX5.3 PHYSICAL RAM 32 gb Because the page space is going high Thanks Murali (12 Replies)
Discussion started by: murali969
12 Replies

2. Shell Programming and Scripting

Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file. I use below code for each operation. sed -e 's/^*//' < check.txt > check1.txt sed '/^\s*$/d' < check1.txt > check2.txt above code not remove all the space... (12 Replies)
Discussion started by: Mohin Jain
12 Replies

3. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

4. Shell Programming and Scripting

remove space

File A.txt A005 -119.5 -119.5 -100.5 A006 -120.5 -119.5 -119.3 A008 0 0 0 Output A005 -119.5 -119.5 -100.5 A006 -120.5 ... (1 Reply)
Discussion started by: asavaliya
1 Replies

5. Shell Programming and Scripting

Dot operator and space, Parameter not set

Hi, i have this script setenv.sh if then echo "is empty" fi echo "done" The following is the result when i run the script from command without and with a dot and space operator $ setenv.sh is empty done $ . setenv.sh sh: VAR_1: Parameter not set. $ It's our standard to run... (5 Replies)
Discussion started by: ysrini
5 Replies

6. Shell Programming and Scripting

Remove last space in a string?

I have a customer file now and would like to separate the names into two cells in a spreadsheet. Here is my data as an example: SHAWN R KEEGAN shawn r scroggin Shawn Regan Shawn Reilly The first two have the middle initial so I'd like to include them in the "first name" field and the last... (11 Replies)
Discussion started by: Grassy
11 Replies

7. Shell Programming and Scripting

Remove space

DATE=6/Jul/2010 6/Jul/2010 var="sed -n '/\ ---------- Post updated at 11:49 AM ---------- Previous update was at 11:36 AM ---------- #!/bin/bash DATE=`./get_date.pl 3` DATE1=`./get_date.pl 2` var1=$( echo "$DATE" | sed "s/ //g" ) var2=$( echo "$DATE1" | sed "s/ //g" ) var="sed -n... (1 Reply)
Discussion started by: sandy1028
1 Replies

8. UNIX for Dummies Questions & Answers

Space in file how to remove

Hello I have a file with data something like this in it : texttexttext "text .lst" TEXT=" text " texttexttext "moretext .lst" TEXT=" text " Question is how do I get rid of space so that the files looks like this : texttexttext "text.lst" TEXT="text" texttexttext... (8 Replies)
Discussion started by: davebw
8 Replies

9. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies

10. Shell Programming and Scripting

remove duplicates within a block in a file..help required

hi.. i have a file in the following format :- name-a age -12 address-123 age-12 phone-22222 ============ name-ab age -11 address-123 age-11 phone-222223 ============= name-abc age -12 address-1234 age-12 phone-2222223 ============= (2 Replies)
Discussion started by: nipun_garg
2 Replies
Login or Register to Ask a Question