LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-08-2005, 07:44 AM   #1
neerajchaudhari
Member
 
Registered: Jun 2005
Location: Pune
Distribution: mandrake
Posts: 30

Rep: Reputation: 15
linux command


hi everyone,
i am a newbie, recently i have installed redhat linux on my machine, while exploring the various commands of linux, i was stuck up at a point, it was

i have a file named abc, the contents of the file are
/usr/local/j2sdk1.4.2_09/lib/tools.jar

now i want to display, the contents of the string apart from the pattern i am using to search through the file.
rather if i specify the pattern "/lib/tools.jar", my result should be the part of the string that is unmatched i.e the result should be
/usr/local/j2sdk1.4.2_09

which is the command that will fetch me the result

waiting eagerly for the reply
thanks in advance
 
Old 09-08-2005, 07:59 AM   #2
pats
Member
 
Registered: Jul 2005
Distribution: Debian Sarge/Etch, (K)Ubuntu, FC6, AIX5.3, VMWare ESXServer
Posts: 159

Rep: Reputation: 30
you need to use a command called grep

have a look at its man pages

man grep

and look at the section on regular expressions in particular.

good luck
 
Old 09-08-2005, 08:05 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

sed 's%\(.*\)/lib/tools.jar\(.*\)%\1\2%' infile

The above command will show all that is in front and behind the search string (/lib/tools.jar). If there's only something in front you could shorten the command to:

sed 's%\(.*\)/lib/tools.jar%\1%' infile

The searchstring itself can be made dynamic too:

SEARCH_THIS="/lib/tools.jar"
sed "s%\(.*\)${SEARCH_THIS}%\1%" infile

Mind the double quotes instead of single quotes in the sed statement.

Hope this helps.
 
  


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
linux command neerajchaudhari Linux - Newbie 1 09-09-2005 03:58 AM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
linux df command glaz Linux - Newbie 9 06-25-2005 11:50 AM
Need some help with linux command NiallC Linux - Newbie 2 11-11-2004 03:47 AM
unix command to linux command leonidas Linux - General 1 09-10-2004 01:40 AM


All times are GMT -5. The time now is 06:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration