Help with grepping and line number


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with grepping and line number
# 1  
Old 12-28-2008
Question Help with grepping and line number

I need help with extracting data from a large file ~900mb. Below is how the data looks like,
line number value
1001 10000
... ...
5001 50000
6001 60000
... ...
10001 100000
... ...
100001 1000000
basically i need to grep lines starting from line 1001 and keep grepping line data for every 1000 after that. this is because after a certain number of lines ******** is displayed for the values which is problematic for my usual grepping scheme and hence my need to use the grep line number method. any help on the command for doing this would be much appreciatedSmilie
# 2  
Old 12-29-2008
Try this:

Code:
awk '{ if ($1 ~ /[0-9]*001/) print; }'  file

# 3  
Old 12-29-2008
i have used the following code previously,
less a.dat | grep ".[0-9][0-9][0-9]0000..." > x.dat
which had worked very well previously but now need to take line number into consideration. is there a command similar to this?Smilie
# 4  
Old 12-29-2008
Question

Quote:
Originally Posted by dennis.jacob
Try this:

Code:
awk '{ if ($1 ~ /[0-9]*001/) print; }'  file

the following is what is output using your code,

...
400160 0.13202E-05 0.37790E-15 7732 -0.83922E-05 0.84854E-05
400170 0.13202E-05 0.38622E-15 7732 -0.83929E-05 0.84873E-05
400180 0.13202E-05 0.40112E-15 7731 -0.83933E-05 0.84888E-05
400190 0.13203E-05 0.41872E-15 7732 -0.83918E-05 0.84899E-05
410010 0.13527E-05 0.36685E-15 7730 -0.82925E-05 0.85203E-05
420010 0.13857E-05 0.30460E-15 7728 -0.83042E-05
...

i would like the bold part to be kept as 0000 and the remaining part before the zeroes to increment as usual [0-9]...
unfortunately did'nt work, but maybe useful code needing a bit of a tweak. thanks anyway.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

2. Shell Programming and Scripting

Returning only part of a line when grepping

I want to grep out a part of a snort rule based on the SID given, but all i want as the output is the part in the quotes after the msg: An example line looks something like this: alert tcp any any -> 127.0.0.1 any (msg:"Example Message"; classtype:Example; sid:123456;) I would want it to... (7 Replies)
Discussion started by: riott
7 Replies

3. Shell Programming and Scripting

regular expression grepping lines with VARIOUS number of blanks

Hi, I need a regular expression grepping all lines starting with '*' followed by a VARIOUS number of blanks and then followed by the string 'Runjob=1'. I tried that code, but it doesn't work: grep -i '*'+'Runjob=1' INPUT_FILE >>OUTPUT_FILE Can someone help me? Thanks (8 Replies)
Discussion started by: ABE2202
8 Replies

4. Shell Programming and Scripting

Grepping Multiple Strings on the Same Line 'Or'

I've got this command that I've been using to find strings on the same line, say I'm doing a search for name: find . -name "*" | xargs grep -i "Doe" | grep -i "John" > output.txt This gives me every line in a file that has John and Doe in it. I'm looking to add a OR operator for the second... (5 Replies)
Discussion started by: Rally_Point
5 Replies

5. UNIX for Dummies Questions & Answers

Grepping nth line number

How do you grep every nth line number from a file? (2 Replies)
Discussion started by: shabs1985
2 Replies

6. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies

7. Shell Programming and Scripting

reading line by line and grepping

I've got a file which I am reading line by line (using read line) into a variable. I then want to do a grep on that line to check for something. I've tried a number of methods none of which seem to work. I thought I had it with the code below but for some reason it doesn't like it and comes... (4 Replies)
Discussion started by: QueryMaster
4 Replies

8. Shell Programming and Scripting

Grepping 1 line above and below pattern

I have a pattern:: xldn3176bap>arj SOCRATES_MAIN_LNX | grep " FA " 10/04/2007 21:01 10/04/2007 21:01 FA 1776752/1 1 I want the line above this line and the line below it too. Can anyone tell me how it can be done? - iAm4Free (4 Replies)
Discussion started by: iAm4Free
4 Replies

9. Shell Programming and Scripting

Grepping number combinations

Having problem in using the grep command to select all possible combinations a number in a file. Example: 123, I would like to grep the numbers 123,132,213,231,312 and 321. (2 Replies)
Discussion started by: wperry
2 Replies

10. UNIX for Dummies Questions & Answers

grepping for something but excluding something else in the line

Ok heres the situation. I'm grepping for all running processes with the name system. but there are also processes running with the name systema. How do I just search for processes running just under the "system" user Thanks in advance (1 Reply)
Discussion started by: fusion99
1 Replies
Login or Register to Ask a Question