How to grep only some part of character?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep only some part of character?
# 1  
Old 02-06-2014
How to grep only some part of character?

Hi,

I have log :

Code:
# cat log

[~/temp]$ cat 4
2014092014
2014102014
2014112023
2014123014
2014010100
2014010101
2014010102
2014010103
2014010104
2014020123
2014020115
2014020116
2014020117
2014020118
2014020119
2014020120
2014020121
2014020122
2014020123
2014020200
2014020201
2014030202
2014033203
2014030204
2014030205
2014030206
2014030207
2014030208
2014030223
2014030210
2014030211
2014030212
2014030213

I want only grep 2014xxxx23 ?

Code:
2014112023
2014020123
2014020123
2014030223

# 2  
Old 02-06-2014
Code:
grep 2014[0-9][0-9][0-9][0-9]23 file

This User Gave Thanks to PikK45 For This Post:
# 3  
Old 02-06-2014
Quote:
Originally Posted by justbow
Hi,
....
I want only grep 2014xxxx23 ?
....
Code:
$ grep  -E '2014[[:digit:]]{4}23' file
2014112023
2014020123
2014020123
2014030223

This User Gave Thanks to Akshay Hegde For This Post:
# 4  
Old 02-06-2014
As long as you know that you're only working with numeric input, a simpler approach is:
Code:
grep '2014....23' file

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract a part of grep output

Hi, On AIX 7 I have : grep 's_ohs_instance_loc' $CONTEXT_FILE <ohs_instance_loc oa_var="s_ohs_instance_loc">/u01/appl_top/env/fs1/FMW_Home/webtier/instances/EBS_web_env_OHS1</ohs_instance_loc> But I need only this part:... (4 Replies)
Discussion started by: big123456
4 Replies

2. Programming

Grep part of dataframe in R?

Seems not very post about R language. Here is one: How to grep a sublist of a list like grep -f in unix? say I have a dataframe ID v1 v2 v3 A 1 3 4 B 4 5 6 C 7 8 9 D 1 3 4 E 1 3 3 F 2 4 5 and I only need ID v1 v2 v3 A 1 3 4 C 7 8 9 E 1 3 3 F 2 4 5 by like grep... (2 Replies)
Discussion started by: yifangt
2 Replies

3. Shell Programming and Scripting

Return part of string after X numbers of a character

My input strings look something like this: /dev/vs/dsk/group/vol I want to print just "group" out of the line... which is always found between the 4th and 5th "/" in the string. I figure I have to use awk, sed, or some combination to do this, but I've searched the forums and can't find... (2 Replies)
Discussion started by: ltricarico
2 Replies

4. UNIX for Dummies Questions & Answers

can I grep a part of one line ?

<exp code="12556a" message="ok, fine4" displayMessage="jksdfj ksd" \> <exp code="123456a" message="ok, 2fine" displayMessage="jksdfj ksd" \> <exp code="12dfgda" message="1ok, fine" displayMessage="jksdfj ksd" \> now I want to cut code attribute and message attribute, such as ... (2 Replies)
Discussion started by: vincent_W
2 Replies

5. Shell Programming and Scripting

How to get a part of the line(need help in using grep)

Hi, Suppose, DBconnection=jdbc: oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=x.x.x.x)(PORT=YYYY))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=project_db1))) This is a part of a file <filename> . I Need to get the value of SERVICE_NAME from this line… The... (4 Replies)
Discussion started by: Dpu
4 Replies

6. UNIX for Dummies Questions & Answers

How to use grep to get only part of a line...

Hello All. I have an output file which contains the phrase "Total DFT Energy =" and then a number. This occurs many times in the output file, and what I want is to pipe the numbers (which are all different) to a file so I can plot them. How do I grep "Total DFT Energy =" and then get the numbers... (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

7. Shell Programming and Scripting

grep part of file name

Hi, I have a problem to use grep in my script . If I want to grep the file for example : PTWO9089.txt The code below works . grep ^PONE But, I dont know on how to grep the file like this 9066PTWO.txt I'll try to use this code : grep PTWO^ ,but it doesn't work. For your info, the... (4 Replies)
Discussion started by: badbunny9316
4 Replies

8. Shell Programming and Scripting

Grep part of the line

How do I print only the values of the variables from set or env. For example I have the lines USER=USER XYZ='text' SHELL=/bin/bash How do I print only the part after or starting from = Let's say I have those lines in a list X If I run Y = echo $X | grep -o "=*$" Y won't contain... (3 Replies)
Discussion started by: Transsive
3 Replies

9. Shell Programming and Scripting

grep a part of a line

Hi, In a file FILE, there is a line like this one MOLECULE C2 H2 I want to extract "C2 H2". I can do it in two step in a script : VARIABLE="`grep MOLECULE FILE`" # Assign "MOLECULE C2 H2" VARIABLE=`echo ${VARIABLE/"MOLECULE "}` # Remove "MOLECULE ". Then, $echo $VARIABLE gives C2... (6 Replies)
Discussion started by: tipi
6 Replies

10. UNIX for Dummies Questions & Answers

grep within certain part of file

Hi, Is it possible to grep only on a certain part of a file? Say I have file in.txt which contains below: 11/16 13:07:19.5436 --- ERROR 123 detected. 11/16 13:08:19.5436 --- Generating a <reading> event 11/16 13:08:19.7784 ---- Sending a <writing> event 11/16 14:08:37.4516 ---... (2 Replies)
Discussion started by: Orbix
2 Replies
Login or Register to Ask a Question