LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2011, 02:14 AM   #1
fad216
LQ Newbie
 
Registered: Feb 2011
Posts: 11

Rep: Reputation: Disabled
remove everything from starting until some keyword


hello everyone...

I have a multiple txt file in one folder. I would like to remove everything from starting until find string keyword in one folder. Here is the sample of my text:
Code:
5a651a62sf1a54f2a1sf6a4f50a5f4a2f1a2d1sfs11231211f61d021sd1fs1Reassembles21f2sdf122dfs21fs212sdfdsf1s65f1s62f1
So i want to remove everything from starting until reassemble. Here is the sample output:

Code:
s21f2sdf122dfs21fs212sdfdsf1s65f1s62f1
I have multiple file in one folder. So how to use any script to read in one directory folder and do a same task. I prefer using awk, sed or perl.

Thank you...
 
Old 03-24-2011, 04:01 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
something like this?

Code:
#!/bin/env perl -p

$y="s21f2sdf122dfs21fs212sdfdsf1s65f1s62f1";

's/.*(?=$y)//'
 
Old 03-24-2011, 04:22 AM   #3
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
split on Reassemble, then get the last element.
Code:
$ ruby -ne 'puts $_.split(/Reassemble/,2)[-1]' file
 
Old 03-24-2011, 04:28 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Code:
$ sed -i 's/^\(.*\)[Rr]eassemble//' *.txt
 
Old 03-24-2011, 06:13 AM   #5
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Quote:
Originally Posted by quanta View Post
Code:
$ sed -i 's/^\(.*\)[Rr]eassemble//' *.txt
you don't need to group if you are not using backreference.
 
1 members found this post helpful.
Old 03-24-2011, 07:10 AM   #6
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
Quote:
you don't need to group if you are not using backreference.
meaning:
sed -i 's/^.*[Rr]eassemble//' *.txt

Last edited by Ramurd; 03-24-2011 at 07:11 AM. Reason: whoops, typo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I remove all lines starting with "-CONFIG_" from a file ? Glenn D. Linux - Kernel 4 10-05-2010 09:36 AM
how to grep a "keyword" beside another keyword? xiawinter Linux - Software 7 12-29-2007 12:50 AM
Directory starting in ...: cannot remove badradiation Linux - General 2 09-15-2007 10:28 PM
How to Remove ndiswrapper from starting. NuxIT Linux - Wireless Networking 2 04-29-2006 01:03 AM
c++ super keyword kuna Programming 4 01-04-2005 07:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration