LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-03-2010, 06:31 AM   #1
mech123
Member
 
Registered: Dec 2008
Posts: 36

Rep: Reputation: 16
search string command


1.i want to know command for search a string in file without opening file from vi editor.
2nd question.when i open file with vi editor in linux, i can search string by (in esc mode) "/search_string" command. This will search string from starting of file what will be command if i want to search string from "end of file" in "vi opened file".
 
Old 01-03-2010, 06:32 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
1. grep.
 
Old 01-03-2010, 06:36 AM   #3
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,034

Rep: Reputation: 65
Quote:
Originally Posted by mech123 View Post
1.i want to know command for search a string in file without opening file from vi editor.
2nd question.when i open file with vi editor in linux, i can search string by (in esc mode) "/search_string" command. This will search string from starting of file what will be command if i want to search string from "end of file" in "vi opened file".
Code:
cat file.txt | grep <pattern>
 
Old 01-03-2010, 06:37 AM   #4
mech123
Member
 
Registered: Dec 2008
Posts: 36

Original Poster
Rep: Reputation: 16
please please describe in proper syntax and what is answer of 2nd question
 
Old 01-03-2010, 06:39 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
You can use various utitlities to search file---eg GREP, SED, AWK

As for the VI question, does the manual (or man page) say anything about this?
 
Old 01-03-2010, 06:39 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by cola View Post
Code:
cat file.txt | grep <pattern>
You don't need the cat - grep pattern file works.
 
Old 01-03-2010, 06:42 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by mech123 View Post
please please describe in proper syntax and what is answer of 2nd question
What do you mean by "proper syntax"? I don't see any syntax mistakes here. For any of these commands, the man page will give you the syntax.

Do you have some kind of reference material? (e.g. the Bash Guide for Beginners)
 
Old 01-04-2010, 10:26 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,237

Rep: Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711
1. grep string file
2. :?string-to-find (? = search backwards)
 
  


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
vim 'n' lynx: command line option to search for string Samsara Linux - Software 6 01-02-2013 06:36 PM
Web Development --- Command to search string through files on a server mobby1982 Programming 2 04-11-2009 06:14 PM
giving search-string(s) from a file to linux "find" command Fond_of_Opensource Linux - Newbie 3 02-02-2009 06:14 PM
Need to search all files for string - strings command? jmur Programming 4 03-28-2008 02:35 PM
Issuing find command to search for string keysorsoze Linux - Newbie 4 11-30-2007 12:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:06 PM.

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