Grep only line starting with....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep only line starting with....
# 1  
Old 07-24-2013
Grep only line starting with....

Hello,
I have a command that show some application information. Now, I have to grep there informations, like:

Code:
# showlog | grep 1266
1266.1369866124 :: 
1266.1304711286 :: 
41031.1161812668 :: 
41078.1301266480 :: 
41641.712662564 :: 
1266.333792515 :: 
41462.1512661988 :: 
1266.54932671 :: 
12666.54345932671 ::

What I need from grep is the line that start with 1266. (with dot) But that string is also contained into other rows and the grep reports wrong output.

The output I'm expecting is:
Code:
1266.1369866124 :: 
1266.1304711286 :: 
1266.333792515 :: 
1266.54932671 ::

Thanks who can help me.
Lucas
# 2  
Old 07-24-2013
Hello,


Could you please try the following and let me know if this helps.


1st way:
Code:
 
$ cat grep_starting | grep '^1266*'

1266.1369866124 ::
1266.1304711286 ::
1266.333792515 ::
1266.54932671 ::
$


2nd Day:

Code:
 
$ awk '/^1266/' grep_starting

1266.1369866124 ::
1266.1304711286 ::
1266.333792515 ::
1266.54932671 ::
$



Kindly try same and let me know if you have any queries.



Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 07-24-2013
Code:
showlog | grep "^1266\."

This User Gave Thanks to Yoda For This Post:
# 4  
Old 07-24-2013
Thanks, this one:
Code:
| grep '^1266*'*


Works perfect!!

EDIT: Also the one provided by Yoda works! Smilie

# 5  
Old 07-24-2013
Note that '^1266*' will return lines starting with 1266 followed by any character:
Code:
1266.1369866124 ::
1266.1304711286 ::
1266.333792515 ::
1266.54932671 ::
12666.54345932671 ::

You should use "^1266\." to get only thoses starting with 1266.

Period is a metacharacter, hence escaped to preserve its literal meaning.
This User Gave Thanks to Yoda For This Post:
# 6  
Old 07-24-2013
Thanks Yoda for information, I was about to say the same.
This User Gave Thanks to RavinderSingh13 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

2. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies

3. 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

4. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

5. Shell Programming and Scripting

Grep command to ignore line starting with hyphen

Hi, I want to read a file line by line and exclude the lines that are beginning with special characters. The below code is working fine except when the line starts with hyphen (-) in the file. for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'` do . . done How... (4 Replies)
Discussion started by: Srinraj Rao
4 Replies

6. Shell Programming and Scripting

How to print line starting with certain string together with its following line?

Dear all, How can I print line starting with certain string together with its following line. Example is as follows: Input file: @M01596:22:000000000-A7YH7:1:1101:16615:1070 2:N:0:1... (2 Replies)
Discussion started by: huiyee1
2 Replies

7. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 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... (2 Replies)
Discussion started by: chrisjorg
2 Replies

8. Shell Programming and Scripting

Grep starting from a specific position

Hello people, I'm scratch my head to find a solution to my problem, I'm absolutely sure this is very simple!!! :wall: I'm using the tcpdump to show on the screen in real time the UCP traffic: tcpdump -l -i bond1 -s 1514 -nntttt -A src or dst 192.168.1.5 and port 10000 | egrep "/51/"The output... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

9. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

10. Shell Programming and Scripting

how to delete text from line starting pattern1 up to line before pattern2?

My data is xml'ish (here is an excerpt) :- <bag name="mybag1" version="1.0"/> <contents id="coins"/> <bag name="mybag2" version="1.1"/> <contents id="clothes"/> <contents id="shoes"/> <bag name="mybag3" version="1.6"/> I want to delete line containing mybag2 and its subsequent... (5 Replies)
Discussion started by: repudi8or
5 Replies
Login or Register to Ask a Question