03-19-2005
Using grep to extract line number
I'm trying to use grep to get the line number only. This is the command I'm using:
grep -n "Content-Disposition: attachment" mbox
The output I get is:
45:Content-Disposition: attachment; filename="test.txt"
So now I just want to get the line number (45) from this output.
Can someone help me with this? Thanks
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hello all
when I do simple grep on file im getting the results of "filename : stringResult "
is there any way to present also the line number in the file ? (1 Reply)
Discussion started by: umen
1 Replies
2. UNIX for Dummies Questions & Answers
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
3. Shell Programming and Scripting
In file.name, I have a line that reads
$IDIR/imgen -usemonths -dropcheck -monitor -sizelimit 80000000 -interval 120 -volcal HSI
How can I get the size limit, i.e. 80000000 out and pass it to a variable called SIZE?
Thanks. I tried
echo "grep sizelimit file.name" | sed -n -e... (3 Replies)
Discussion started by: rodluo
3 Replies
4. Shell Programming and Scripting
I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script
# Get randome line number from the file
#selectedline = `awk... (1 Reply)
Discussion started by: zambo
1 Replies
5. Shell Programming and Scripting
Hello,
I am having trouble extracting a specific line from a file when the line number is known. My first attempt involved grep -n 'hi' (the word 'hi will always be there) to get the line number before the line that I actually want (line 4).
Extra Notes:
-I am working in a bash script.
-The... (7 Replies)
Discussion started by: grandtheftander
7 Replies
6. UNIX for Dummies Questions & Answers
Hello,
I have a question regarding the awk command. Here is the line I need to grep:
1 F= -.13250138E+03 E0= -.13249556E+03 d E =-.174650E-01 mag= 35.2157
Instead of displaying the number in red I would like to store it as a variable such as X. Is there a way to do this? Thanks for any... (3 Replies)
Discussion started by: modey3
3 Replies
7. Shell Programming and Scripting
Hi
I want to extract certain text between two line numbers like
23234234324 and
54446655567567
How do I do this with a simple sed or awk command?
Thank you.
---------- Post updated at 06:16 PM ---------- Previous update was at 05:55 PM ----------
found it:
sed -n '#1,#2p'... (1 Reply)
Discussion started by: return_user
1 Replies
8. Shell Programming and Scripting
Hi,
I search all forum, but I can not find solutions of my problem :(
I have multiple files (5000 files), inside there is this data :
FILE 1:
1195.921 -898.995 0.750312E-02-0.497526E-02 0.195382E-05 0.609417E-05
-2021.287 1305.479-0.819754E-02 0.107572E-01 0.313018E-05 0.885066E-05
... (15 Replies)
Discussion started by: guns
15 Replies
9. Shell Programming and Scripting
Hi guys,
does anyone know how to extract(grep) a line from the file, if I know the line number?
Thanks a lot. (9 Replies)
Discussion started by: aoussenko
9 Replies
10. Shell Programming and Scripting
Hi. im trying to retrieve the line number from grep. i have 1 part of my code here.
grep -n $tgt file.txt | cut -f 1 -d ":"
when i do not cut the value i have is 12:aaa:abc:aaa:aaa:aaa
how can i store the value of 12 or my whole line of string into a variable with grep? (6 Replies)
Discussion started by: One_2_three
6 Replies
READFILE(3) 1 READFILE(3)
readfile - Outputs a file
SYNOPSIS
int readfile (string $filename, [bool $use_include_path = false], [resource $context])
DESCRIPTION
Reads a file and writes it to the output buffer.
PARAMETERS
o $filename
- The filename being read.
o $use_include_path
- You can use the optional second parameter and set it to TRUE, if you want to search for the file in the include_path, too.
o $context
- A context stream resource.
RETURN VALUES
Returns the number of bytes read from the file. If an error occurs, FALSE is returned and unless the function was called as @readfile(3),
an error message is printed.
EXAMPLES
Example #1
Forcing a download using readfile(3)
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
The above example will output something similar to:[NOT DISPLAYABLE MEDIA]Open / Save dialogue
NOTES
Note
readfile(3) will not present any memory issues, even when sending large files, on its own. If you encounter an out of memory error
ensure that output buffering is off with ob_get_level(3).
Tip
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to
specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers
have, notes on their usage, and information on any predefined variables they may provide.
Note
Context support was added with PHP 5.0.0. For a description of contexts, refer to "Streams".
SEE ALSO
fpassthru(3), file(3), fopen(3), include(3), require(3), virtual(3), file_get_contents(3), "Supported Protocols and Wrappers".
PHP Documentation Group READFILE(3)