AWK/GREP: grep only lines starting with integer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK/GREP: grep only lines starting with integer
# 1  
Old 04-17-2012
AWK/GREP: grep only lines starting with integer

I have an input file

Code:
12.4 1.72849432773174e+01 -7.74784188610632e+01
12.5 9.59432114416327e-01 -7.87018212757537e+01
15.6 5.20139995965960e-01 -5.61612429666624e+01
29.3 3.76696387248366e+00 -7.42896194101892e+01
32.1 1.86899877018077e+01 -7.56508762501408e+01
35 6.98857157014640e+00 -6.47719177518354e+01
57.5 9.93224752487084e+00 -5.98507250538671e+01
59.5 1.17880137446671e+01 -6.70358856818233e+01
59.6 3.39353476095376e+00 -5.85719268969042e+01
64.6 1.39100633884576e+01 -7.89068504596848e+01
66.1 3.29754641066104e+00 -6.11126946124472e+01
68.3 1.34614891224838e+01 -7.96561570561526e+01
75.2 1.27732250188725e+00 -7.98537412569579e+01
75.7 1.81103716761368e+01 -7.96494146285998e+01
79.6 6.16383337522536e+00 -6.29030439858399e+01
92.8 1.52331049249522e+01 -6.51748608352182e+01
94.6 7.26150084491214e+00 -6.93621024271574e+01
100.1 1.68539103307157e+01 -7.85748993775416e+01
100.9 3.52929142412477e+00 -6.86640757476861e+01
101 1.62464294145481e+00 -6.12247635460096e+01
101.1 1.67667000571671e+01 -7.60963191396523e+01
109.1 1.89539766434845e+01 -3.22357460422950e+01
124.2 5.77306017328185e+00 -7.74816073271627e+01
124.3 1.62709216276807e-01 -6.38710866726218e+01
124.4 1.62418063967260e+00 -5.06164124324214e+01
124.5 1.15920020337606e+00 -5.39562951251459e+01
127.5 1.63638664576208e+01 -7.53341787458119e+01

I want to grep only lines that start with an integer number,

any recommendations?
# 2  
Old 04-17-2012
Code:
awk '$1 ~ /^[0-9]*$/' file


Last edited by neutronscott; 04-17-2012 at 10:59 AM.. Reason: oops
# 3  
Old 04-17-2012
Try:
Code:
awk '$1~/^[0-9]+$/' infile

Code:
awk '$1!~/[^0-9]/' infile

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 grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

3. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

4. Shell Programming and Scripting

grep/awk to only print lines with two columns in a file

Hey, Need some help for command to print only lines with two columns in a file abc 111 cde 222 fgh ijk 2 klm 12 23 nop want the ouput to be abc 111 cde 222 ijk 2 Thanks a lot in advance!!! (3 Replies)
Discussion started by: leo.maveriick
3 Replies

5. Shell Programming and Scripting

Problems to print specific lines with awk and grep...HELP!

Hi all I have data like this: model: 1, misfit value: 0.74987 1 1.182 1.735 2.056 1.867 2 0.503 1.843 2.018 1.888 3 2.706 2.952 2.979 1.882 4 8.015 3.414 3.675 1.874 ... (1 Reply)
Discussion started by: fedora2011
1 Replies

6. UNIX for Dummies Questions & Answers

grep/awk and bring multiple lines forward

Hello all, I have a question regarding grep and pulling the result forward to the next carriage return or line space. Sorry if I have terminology incorrect. I have the following data set. Line1 Line2 Line3 Line5 Line6 Line7 Line9 Line10 Line11 I would like to grep for a pattern... (5 Replies)
Discussion started by: klysdale
5 Replies

7. Shell Programming and Scripting

use awk pick value from lines as condition for grep

Hi Folks! I have a file like this 000000006 dist:0.0 FILE ./MintRoute/MultiHopWMEWMA.nc LINE:305:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:733 TEID:758 000000000 dist:0.0 FILE ./Route/MultiHopLEPSM.nc LINE:266:1 NODE_KIND:131 nVARs:4 NUM_NODE:66 TBID:601 TEID:626 000000001 ... (2 Replies)
Discussion started by: jackoverflow
2 Replies

8. UNIX for Dummies Questions & Answers

retrieve lines using sed, grep or awk

Hi, I'm looking for a command to retrieve a block of lines using sed or grep, probably awk if that can do the job. In below example, By searching for words "Third line2" i'm expecting to retrieve the full block starting with 'BEGIN' and ending with 'END' of the search. Example: ... (3 Replies)
Discussion started by: learning_linux
3 Replies

9. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

10. UNIX for Dummies Questions & Answers

awk or grep for integer only

how do you print the lines that contain integers only, using grep or awk? thanks , apalex ------------------ this file below: qwerty 01234 asdfgh 01234 qwer12 asdf05 will be: 01234 01234 qwer12 asdf05 (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question