Sponsored Content
Top Forums Shell Programming and Scripting Match String and get line number and filename Post 302269261 by bakunin on Wednesday 17th of December 2008 07:31:23 AM
Old 12-17-2008
Quote:
Originally Posted by thenz
find $dir -type f -exec grep $string {} \;
You were almost there. First, add the filename:

Code:
find $dir -type f -exec grep $string {} \; -print

Then - you got that explained already - use "grep -n" to get the line numbers:

Code:
find $dir -type f -exec grep -n $string {} \; -print

I suggest reading a man page now and then if you encounter a program or a program call you don't understand fully, like the "-n" switch in "grep". You could have looked up "-n" on the man page of grep and find out this way what its purpose is. This is generally a fruititious approach.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Get Filename and Line Number using grep

Hi, I am using the Korne shell to try and get the filename, line number and the line of text using grep e.g. find ./ -type f -name "*.java" -exec grep -nf test.txt '{}' \; (test.txt contains strings to search) will return the line number and the line of text. grep -l would return the... (4 Replies)
Discussion started by: ceemh3
4 Replies

2. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies

3. Shell Programming and Scripting

Getting filename for Nth line pattern match

Hi, I have many scripts in particular directory. And few of the scripts have exit 0 in second line. Now i wanted to list out the scripts name which has the exit 0 in its second line I tried many options , but i can not get the filename along with the nth line pattern match :mad:. Can anyone... (14 Replies)
Discussion started by: puni
14 Replies

4. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

5. Shell Programming and Scripting

Grep range of lines to print a line number on match

Hi Guru's, I am trying to grep a range of line numbers (based on match) and then look for another match which starts with a special character '$' and print the line number. I have the below code but it is actually printing the line number counting starting from the first line of the range i am... (15 Replies)
Discussion started by: Kevin Tivoli
15 Replies

6. Shell Programming and Scripting

Adding filename and line number from multiple files to final file

Hi all, I have 20 files (file001.txt upto file020.txt) and I want to read them from 3rd line upto end of file (line 1002). But in the final file they should appear to start from line 1. I need following kind of output in a single file: Filename Line number 2ndcolumn 4thcolumn I... (14 Replies)
Discussion started by: bioinfo
14 Replies

7. Shell Programming and Scripting

Deleting double quoted string from a line when line number is variable

I need to remove double quoted strings from specific lines in a file. The specific line numbers are a variable. For example, line 5 of the file contains A B C "string" I want to remove "string". The following sed command works: sed '5 s/\"*\"//' $file If there are multiple... (2 Replies)
Discussion started by: rennatsb
2 Replies

8. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

9. Shell Programming and Scripting

Get remaining line after string match

Want to get the remaining line after pattern match Here it starts - executed commands : - pattern to identify 100:27:500:1:34:END Required output:100:27:500:1:34:END awk '{if(/pattern to identify/) print $2}' < file I have used above code and it not giving... (3 Replies)
Discussion started by: rozee
3 Replies

10. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

Hi everyone :) I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan. Using the code below i am able to generate an image with the slogan text from each line. The image filename is saved matching the last word on each line. Example: Line 1: We do... (2 Replies)
Discussion started by: martinsmith
2 Replies
Rscript(1)								FSF								Rscript(1)

NAME
Rscript - front end for scripting with R SYNOPSIS
Rscript [--options] [-e expr] file [args] DESCRIPTION
A binary front-end to R, for use in scripting applications. expr An optional expression to be evaluated, used in place of expr. file Input file of R expressions args Optional further arguments to be processed by commandArgs in the R interpreter. OPTIONS
--options accepted are --help Print usage and exit --version Print version and exit --verbose Print information on progress --default-packages=list Where 'list' is a comma-separated set of package names, or 'NULL' and also options to R (in addition to --slave --no-restore), such as --save Do save workspace at the end of the session --no-environ Don't read the site and user environment files --no-site-file Don't read the site-wide Rprofile --no-init-file Don't read the user R profile --restore Do restore previously saved objects at startup --vanilla Combine --no-save, --no-restore, --no-site-file --no-init-file and --no-environ SEE ALSO
R(1) R scripting April 2007 Rscript(1)
All times are GMT -4. The time now is 10:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy