How to delete dynamic pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to delete dynamic pattern
# 1  
Old 07-26-2007
How to delete dynamic pattern

Dear Alll

I have 16 columns,in my data file.In my 16th column i m getting unwanted data like /186.how to remove it.The value in 16th column is dynamic.

Data:
-----
25|1059530000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100|14655/186
25|1059530001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100|14655/184
8728|2040701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100|0/0
8728|2040701617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100|14655/191


Thus i want to remove those Bolded data from the line.My output should be as follows.
25|1059530000|9305282846|355780600|100|1|0|4:UPE0|241|1|4121|2|0|100|100|14655
25|1059530001|9305282847|355780670|100|2|0|4:UPE0|241|1|4121|2|0|100|100|14655
8728|2040701618|9358642959|332661308|100|0|0|4:UPW0|243|1|4616|2|0|100|100|0
8728|2040701617|9358642958|332661253|100|2|0|4:UPW0|243|1|4616|2|2|100|100|14655

can i do this in sed or awk.The error is only in 16th column.records to be deleted 10 million.
# 2  
Old 07-26-2007
Code:
sed 's:/.*::' input_file > output_file

# 3  
Old 07-26-2007
can u explain..

Quote:
Originally Posted by Shell_Life
Code:
sed 's:/.*::' input_file > output_file

Can u just explain why u r using .*::.
or just tel whether it is replacing all the charecters after / or it is deleting .
# 4  
Old 07-26-2007
The 'sed' command 's:/.*::' removes from all lines strings that begin with '/'.
# 5  
Old 07-26-2007
Code:
sed 's#\(.*\)|.*/.*$#\1#' myFile

# 6  
Old 07-26-2007
Quote:
Originally Posted by vgersh99
Code:
sed 's#\(.*\)|.*/.*$#\1#' myFile

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

# 7  
Old 07-26-2007
If my data contains address...

Quote:
Originally Posted by Shell_Life
The 'sed' command 's:/.*::' removes from all lines strings that begin with '/'.
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
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