sed - remove space and . for a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - remove space and . for a pattern
# 1  
Old 03-04-2015
sed - remove space and . for a pattern

Hi,

I have file which contains following lines
Code:
A| 965.|Mr.|35.45| 66.
B| 33.| a456.| 77.

The output should be
Code:
A|965|Mr.|35.45|66
B|33| a456.|77

Basically if a Number has space in prefix and . in suffix remove both.
So pattern could be if there is a | which has next two characters as space and number ending with a number.| remove space and .

The line below removes dot if "number.|" pattern occurs
Code:
sed -i -e 's/\ ([0-9]\).|/\1|/g' -e 's/\ ([0-9]\).$/\1/' file

I need something to search for
"| number" and make it |number

Thanks

---------- Post updated at 05:19 PM ---------- Previous update was at 04:06 PM ----------

Hi,

I almost got what I wanted:
Code:
sed -i -e 's/\([0-9]\).|/\1|/g' -e 's/\([0-9]\).$/\1/' -e 's/|\s\([0-9]\)/|\1/g' file

# 2  
Old 03-04-2015
This one works with your example:
Code:
sed 's/ \([0-9][0-9]*\)\./\1/g' file

---------- Post updated at 05:44 PM ---------- Previous update was at 05:36 PM ----------

This one works according to your description:
Code:
sed 's/^/|/; s/$/|/; s/| \([0-9][0-9]*\)\.|/|\1|/g; s/^|//; s/|$//' file

It treats the following example line differently:
Code:
A|965|Mr. 90.|35.45|66

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove space with sed

Hello Folks , myfile contains 1000000 records as follows: logver=56 idseq=63256 itime=1111 devid=TG-40 devname=PUI-C2 vd=USER date=2019_01_10 time=18:39:49 logid="000013" type="traffic" subtype="forward" level="notice" eventtime=134 srcip=1.1.1.1 srcport=1 srcintf="XYX-CORE.01"... (3 Replies)
Discussion started by: arm
3 Replies

2. Shell Programming and Scripting

How to remove tab space and new line from a file using sed?

i am using the default sed package that comes with solaris. (11 Replies)
Discussion started by: chidori
11 Replies

3. Shell Programming and Scripting

Sed pattern space/looping conundrum

Although my sed skills are gradually developing, thanks in large part to this forum, I'm having a hard time dealing with pattern space and looping, which I suspect is what I'll need a better handle on to figure out my current issue, which is converting a multi line file like this: ... (4 Replies)
Discussion started by: tiggyboo
4 Replies

4. Shell Programming and Scripting

sed pattern and hold space issues

Good day. Trying to make a sed script to take text file in a certain format and turn it into mostly formatted html. I'm 95% there but this last bit is hurting my head finally. Here's a portion of the text- Budgeting and Debt: Consumer Credit Counseling of Western PA CareerLink 112... (5 Replies)
Discussion started by: fiendracer
5 Replies

5. Shell Programming and Scripting

[solved] remove pattern with sed

Hi, i want to remove a certain pattern when i type pwd. pwd will look like this: ..../....../....../Pat_logs/..../....../...../...... the dotted lines are just random directory names, i want it to remove the "Pat_logs/...../....../....../" part so for example: ... (8 Replies)
Discussion started by: a27wang
8 Replies

6. Shell Programming and Scripting

remove pattern with sed

Hi, i want to remove a certain pattern when i type pwd. pwd will look like this: ..../....../....../Pat_logs/..../....../...../...... the dotted lines are just random directory names, i want it to remove the "Pat_logs/...../....../....../" part so for example: ... (5 Replies)
Discussion started by: a27wang
5 Replies

7. Shell Programming and Scripting

Duplicate pattern space (sed)

Hi, I'm new to sed and i'm having a few difficulties.. I need to append the current line to the pattern space, which already contains that same line, e.g.: current line : test pattern space : test|test I was able to do this using the hold space, but the problem is that in the next step of... (2 Replies)
Discussion started by: delucasvb
2 Replies

8. UNIX for Dummies Questions & Answers

blank space in regex pattern using sed

why does sed 's/.* //' show the last word in a line and sed 's/ .*//' show the first word in a line? How is that blank space before or after the ".*" being interpreted in the regex? i would think the first example would delete the first word and the next example would delete the second... (1 Reply)
Discussion started by: glev2005
1 Replies

9. Shell Programming and Scripting

How to remove space in sed for / character

Hi... i need a script to remove the space before and after the operator like( / ). Ex : Input file apple / manago mango / fresh apple / fresh Desired output: apple/manago mango/fresh apple/fresh Note: betwee the desired operator space should be removed, between words do not remove... (3 Replies)
Discussion started by: vasanth_vadalur
3 Replies

10. Shell Programming and Scripting

sed remove everything up to the pattern

I have been search all over the internet to find a solution to this. I have a file that looks like: -a ItemConfig.custom=true -a Config.custom=true go -t malu -t Use=true I want to get "malu" as output, and the werid thing is the blank before go is neither space nor tab. what's the sed... (4 Replies)
Discussion started by: katrvu
4 Replies
Login or Register to Ask a Question