How to delete dynamic pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to delete dynamic pattern
# 8  
Old 07-26-2007
Quote:
Originally Posted by Shell_Life
Vgersh,
Your solution removed the last field entirely including the vertical bar '|'.

See the output for the sample data given by the OP:
Code:
25|1050000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100
25|1050001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100
8728|2701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100
8728|201617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100

sorry - misread the OP's requirement.
# 9  
Old 07-26-2007
Quote:
Originally Posted by tkbharani
Incase if my data contains a address field as follows..
0|6799834|3/4,FirstMain road,Mumbai/Maharashtra|789898|0/787
then how i will remove the last /787 only.In case of
sed 's:/.*::' input_file > output_file
it would remove all charecters form /4,FirstMain road,Mumbai/Maharashtra|789898|0/787
Correct me if i am wrong
.Thanx
Tkbharani,
One of the most important rules when asking to solve a problem is
to give all pertinent details of the problem.

I gave a solution based on your sample data.

You asked for a plain burger and now you want it with mustard, mayonese,
french fries and milkshake.
# 10  
Old 07-26-2007
Code:
sed 's:/[0-9]\{1,3\}$::' input_file

# 11  
Old 07-26-2007
ok yar....

Quote:
Originally Posted by Shell_Life
Tkbharani,
One of the most important rules when asking to solve a problem is
to give all pertinent details of the problem.

I gave a solution based on your sample data.

You asked for a plain burger and now you want it with mustard, mayonese,
french fries and milkshake.
ok..ok...its just some Curiosity yar. Now pls can u give me some mustard, mayonese,
french fries and milkshake. I am in need of it...yar
# 12  
Old 07-27-2007
I'm also interested in this solution.
I could do this using awk but could not do the same in sed.

My interest in this solution is purely academical ( I don't have 10 million records to parse Smilie )

Any solution??
# 13  
Old 07-27-2007
Assuming the data does not contain "~", how about?
Code:
sed 's/|/~/15;s:~\([^|/]*\)/\{0,1\}[^|]*:|\1:'

I'm curious, how do you do it in awk?

Last edited by kahuna; 07-27-2007 at 10:46 AM.. Reason: Oops correct code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete all lines before a particular pattern when the pattern is defined in a variable?

I have a file Line 1 a Line 22 Line 33 Line 1 b Line 22 Line 1 c Line 4 Line 5 I want to delete all lines before last occurrence of a line which contains something which is defined in a variable. Say a variable var contains 'Line 1', then I need the following in the output. ... (21 Replies)
Discussion started by: Soham
21 Replies

2. Shell Programming and Scripting

Pattern find and delete

Hi Team, Could someone please help me on this .. While doing my day to day activity I use to delete manually the repeated ones .. For example 05 & 06 are my hosts.. Now I need to print only 05 and 06, 05-06 is not required. This is how I generate my report daily .. DBG-STG1-05... (5 Replies)
Discussion started by: Nallachand
5 Replies

3. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

4. Shell Programming and Scripting

Delete a pattern using sed.

I have a string in which i need to match a pattern and then i need to delete that line which contains that matching string. The string is .. This is the given string //abc/def/IC.5.4.3/test/... i need to match //abc I am writing like this sed '/^/\/\abc/d' but it is not giving me... (4 Replies)
Discussion started by: codecatcher
4 Replies

5. Shell Programming and Scripting

sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows. header for file 1111 2222 3333 header for file 1111 2222 3333 header for file... (8 Replies)
Discussion started by: gary_w
8 Replies

6. Homework & Coursework Questions

delete line containing a pattern!!!

if the given pattern exists in the file with the very next line starting and ending with the same pattern , delete the line that starts and ends with the given pattern. So upon running on this file ===================== hai people<PATTERN> we had <PATTERN>a lot of fun<PATTERN> ... (1 Reply)
Discussion started by: jacky29
1 Replies

7. Shell Programming and Scripting

how to make pattern search dynamic in awk

Hi, I have a data in a file like below - andy 22 abc 30000 wallstreet paul 30 xyz 40000 martstreet john 35 abc 50000 martstreet I want to search number of employees working in a particular company. Below query executes perfectly - awk '/abc/{ COUNT ++; }END { print "number of... (3 Replies)
Discussion started by: shell123
3 Replies

8. Shell Programming and Scripting

delete line after pattern

Hi, Before insert, delete everything. If ' available before insert, then we need to keep this. Input: ==== l_s := ' INSERT INTO TEST1' INSERT INTO TEST2 Output: ==== 'INSERT INTO TEST' INSERT INTO TEST2 (2 Replies)
Discussion started by: saurabhbaisakhi
2 Replies

9. Shell Programming and Scripting

Delete Lines between the pattern

Hi All, Below is my requirement. Whatever coming in between ' ', needs to delete. Input File Contents: ============== This is nice 'boy' This 'is bad boy.' Got it Expected Output =========== This is nice This Got it (4 Replies)
Discussion started by: susau_79
4 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question