Deleting pattern without removing line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting pattern without removing line
# 1  
Old 09-07-2011
Deleting pattern without removing line

I am trying to delete a pattern without removing line. I searched a lot in this forum and using those I could come up with sed command but it seems that command does not work. Here's how my file looks like:


Code:
1 ./63990 7
1171 ./63990 2
2425 ./63990 9
2539 ./63990 1
3125 ./63990 1
10141 ./63990 1
10968 ./63990 1
11571 ./63990 2
11755 ./63990 1
12757 ./63990 1
13679 ./63990 1
13813 ./63990 4
14349 ./63990 1
14396 ./63990 13
16376 ./63990 1
17846 ./63990 3

I want my output to be like this:

Code:
1 63990 7
1171 63990 2
2425 63990 9
2539 63990 1
3125 63990 1
10141 63990 1
10968 63990 1
11571 63990 2
11755 63990 1
12757 63990 1
13679 63990 1
13813 63990 4
14349 63990 1
14396 63990 13
16376 63990 1
17846 63990 3

This is what I tried but to no avail:

Code:
sed "s/.\///g" file

In Linux with BASH
# 2  
Old 09-07-2011
Code:
sed 's/\.\///g' file

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 09-07-2011
Quote:
cat <filename> | tr '. '/ ' '
This User Gave Thanks to gowtham.varma For This Post:
# 4  
Old 09-07-2011
Code:
$ nawk -F"[./]" '{print $1,$3}' infile

This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 09-07-2011
Quote:
Originally Posted by shoaibjameel123
I am trying to delete a pattern without removing line. I searched a lot in this forum and using those I could come up with sed command but it seems that command does not work.
<snip>
This is what I tried but to no avail:
Code:
sed "s/.\///g" file

In Linux with BASH
Others have offered alternative solutions but no-one has told you why your solution did not work. The dot (.) is a special character in sed and other other languages that use regular expressions to mean match any character. So the dot needs to be escaped in this situation.

It is also worth noting that you can change the delimiters in your sed expression:
Code:
sed 's^\./^^g' file

Funnily enough I tried your solution and it worked. How was it not working?

Andrew
This User Gave Thanks to apmcd47 For This Post:
# 6  
Old 09-07-2011
That's great answer. Smilie

But indeed the regex that I posted wasn't working at my end (I really don't know why as I am not an expert in analysing such regex codes) but the solutions given above did work out.

Thanks for pointing out the shortcoming of my expression. I really appreciate that.
# 7  
Old 09-07-2011
Quote:
Originally Posted by jayan_jay
Code:
$ nawk -F"[./]" '{print $1,$3}' infile

Code:
awk -F"[./]" '$1=$1' file

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

2. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

3. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

4. Shell Programming and Scripting

Removing spaces from line matching a pattern

Hi, I want to remove the spaces from all the lines matching a particular pattern from my file. For instance in file abc.txt I have following data. Header,This is the header 111,this is 1st record 222, this is 2nd record 333, this is 3rd record Footer,3 records found Footer,111222333 ... (5 Replies)
Discussion started by: decci_7
5 Replies

5. Shell Programming and Scripting

Removing a pattern in a line

Dear team, I have a file curve.csv which is generated from oracle and each line has a comment associated with it, I want to get rid of this comment, can you please suggest me a command as how to do it Eg, cat curve.csv /*data for today curve*/ /*data for text1*/ this is the header /*data... (6 Replies)
Discussion started by: infyanurag
6 Replies

6. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

7. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

8. Shell Programming and Scripting

retaining only the second line with a pattern and deleting all others

Hi, I have a file: 5 T1AxialPremosaic ok 512 448 23 1 284000-000005-000001.dcm 6 T2_SPACE ok 256 256 176 1 465000-000006-000001.dcm 7 FLAIRmosaic ok 512 432 23 1 748000-000007-000001.dcm 8 T2_SPACE ok 256 256 1 171000-000008-000001.dcm 9 T2_SPACE ok 256 256 1 218000-000009-000001.dcm... (5 Replies)
Discussion started by: goodbenito
5 Replies

9. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

10. Shell Programming and Scripting

removing a line containing a pattern in sed

i need to use sed to remove an entire line containing a pattern stored in a variable say $var1 this var1 will be a URL and will therefore contain slashes any help would be greatly appreciated (1 Reply)
Discussion started by: Fire_Storm
1 Replies
Login or Register to Ask a Question