LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 12-28-2005, 02:27 AM   #1
mannahazarika
Member
 
Registered: Dec 2005
Location: Dibrugarh, Assam, India
Distribution: Fedora, Debian, Suse
Posts: 40

Rep: Reputation: 15
string manipulation


suppose i want to find a pattern with grep, sed or awk,is there any way by which i can print what is in the right hand side of that pattern till the end of the line.
 
Old 12-28-2005, 03:59 AM   #2
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Code:
>cat file
patternis this the requirement

>sed -e 's/pattern//' file
is this the requirement

Is this your question?
 
Old 12-28-2005, 04:25 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
more correctly:

Code:
sed -e 's/.*pattern//'
 
Old 12-28-2005, 07:56 AM   #4
mannahazarika
Member
 
Registered: Dec 2005
Location: Dibrugarh, Assam, India
Distribution: Fedora, Debian, Suse
Posts: 40

Original Poster
Rep: Reputation: 15
okay let me try them and i will inform that.
what if i want to print the info between 2 words/patterns.
e.g.
let the following line exists in a file.

this is pattern1 and this is pattern2.

if i want to pring between pattern1 and pattern2 i.e. "and this is"
then how to do it?
 
Old 12-28-2005, 08:01 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
sed -e 's/.*pattern1\(.*\)pattern2.*/\1/'
should do it
or, same amount of typing
perl -pe 's/.*pattern1(.*)pattern2.*/$1/'

Last edited by bigearsbilly; 12-28-2005 at 08:08 AM.
 
Old 12-28-2005, 08:03 AM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Code:
echo "this is pattern1 and this is pattern2" | sed -e 's/.*pattern1//;s/pattern2//'
 
Old 12-31-2005, 11:02 AM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Why do people always type the -e option when they're only using a single command? Must like typing, I guess.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Filename string manipulation jango77 Linux - Newbie 2 03-27-2005 06:58 PM
bash + string manipulation dave bean Programming 7 02-16-2005 11:16 AM
String manipulation with a script. philipina Programming 4 03-16-2004 02:42 PM
String manipulation with a script? philipina General 1 03-15-2004 12:07 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration