remove anything after repeated string pattern found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove anything after repeated string pattern found
# 1  
Old 02-06-2012
remove anything after repeated string pattern found

HI,
Can anyone help me with a script.

i/p
Code:
calc 1 2 3 4 5 6 7 8
calc 4 5 6 calc 7 8 9

o/p
Code:
calc 1 2 3 4 5 6 7 8
calc 4 5 6

i.e remove anything after where two times the string calc is found.

thanks

Last edited by Franklin52; 02-06-2012 at 06:45 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 02-06-2012
Code:
perl -pe 's/(calc.*?)calc.*/$1/g' inputfile

# 3  
Old 02-06-2012
Code:
$ sed 's/\(calc.*\) calc.*/\1/' input.txt
calc 1 2 3 4 5 6 7 8
calc 4 5 6

# 4  
Old 02-06-2012
Code:
$ sed 's/ c.*//' input.txt
calc 1 2 3 4 5 6 7 8
calc 4 5 6

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 extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

2. 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

3. Shell Programming and Scripting

need to print lines between repeated pattern

Hi all, I have a file that looks like this: uid=bessemsj version: 1 dn: cn=Desk SpecialAdminDesk, ou=Desks, dc=DSS,c=nl,o=Vodafone dn: cn=DSS Advisors, ou=Groups, dc=DSS,c=nl,o=Vodafone dn: cn=DSS Dispatcher,ou=Groups,dc=DSS,c=nl,o=Vodafone dn: cn=Desk Retention Desk,ou=Desks,... (13 Replies)
Discussion started by: Eman_in_forum
13 Replies

4. Shell Programming and Scripting

remove brackets and put it in a column and remove repeated entry

Hi all, I want to remove the remove bracket sign ( ) and put in the separate column I also want to remove the repeated entry like in first row in below input (PA156) is repeated ESR1 (PA156) leflunomide (PA450192) (PA156) leflunomide (PA450192) CHST3 (PA26503) docetaxel... (2 Replies)
Discussion started by: manigrover
2 Replies

5. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. UNIX for Dummies Questions & Answers

To get the total of how many times the pattern is repeated.

Hi, I need the total of how many times the pattern is being repeated in a particular file. I tried with grep as below, but no go. grep -c best sample Contents of Sample file: ----------------------- This is the best site I have never come across. The best one indeed. Very best... (8 Replies)
Discussion started by: venkatesht
8 Replies

8. Shell Programming and Scripting

Repeated Pattern

I have a list like this: todu todo tofe tafo I want to grep only the lines where the 2nd and the 4th character are the same. In this case I would get only "todo". Thanks. (3 Replies)
Discussion started by: rlopes
3 Replies

9. Shell Programming and Scripting

place delimiter when found repeated occurance

Hi all, Searched lot in the forum but couldnt find relative post to my requirement..Looking forward for the solution. I am basically having a huge file with repeated digits which is getting tuff to track so would want to place a delimiter in between for better clarity.. Input 4 0 4... (1 Reply)
Discussion started by: shaliniyadav
1 Replies

10. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies
Login or Register to Ask a Question