grep particular characters help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep particular characters help
# 1  
Old 08-06-2012
grep particular characters help

Hello folks i have file which is below, i want to extract last column of file that contains dm-21 or dm-13 or dm-N

Quote:

Aug 5 04:15:32 server kernel: ournald(4108): WRITE block 15661624 on dm-21
Aug 5 07:20:15 server kernel: <7(4108): WRITE block 315165328 on dm-21
Aug 5 07:20:15 server kernel: ck 315168240 on dm-21
Aug 5 07:20:15 server kernel: <d(4108): WRITE block 12050472 on dm-21
Aug 5 07:20:15 server kernel: d(4108): WRITE block 12050480 on dm-21
Aug 5 07:20:15 server kernel: <74108): WRITE block 12050504 on dm-21
Aug 5 07:20:15 server kernel: 8): WRITE block 316000544 on8): WRITE block 31600058): WRITE b8): WRITE bloc
k 316000568 on dm-21
Aug 5 07:20:15 server kernel: <8): WRITE block 316006424 on dm-21
Aug 5 07:20:15 server kernel: 8): WRITE block 316006432 on dm-21
Aug 5 07:20:15 server kernel: <74108): WRITE block 3160404108): WRITE block 316045440 4108): WRITE urnald(
4108): WRITE block 316049760 on dm-21
Aug 5 07:45:14 server kernel: <7E block 314216256 on dm-14
Aug 5 07:45:14 server kernel: <7E block 314216264 on dm-21E block 314216272 on dm-21
Aug 5 07:45:14 server kernel: E block 314216512 on dm-21
Aug 5 07:45:14 server kernel: <E block 314216576 on dm-21
Aug 5 07:45:14 server kernel: <E block 314216624 on dmE block 314216632 on dm-21
Aug 5 07:45:14 server kernel: <7(4108): WRITE block 314307720 on dm-18
it show output like

Quote:

dm-21
dm-7
dm-8
I have tried but i got this

Quote:
command

perl -lane 'print $F[-1]' /var/log/messages |grep -e "dm-*" > dm
Quote:
output

dm-4
dm-5
<dm-8
dm-8
<dm-8dm-8
dm-8dm-8
dm-9
<dm-dm-17
<dmdm-17
dm-dm-21
<dm-dm-8
dm-dm-8

Last edited by learnbash; 08-06-2012 at 12:09 PM..
# 2  
Old 08-06-2012
Code:
echo 'Aug 5 04:15:32 server kernel: ournald(4108): WRITE block 15661624 on dm-21' | sed 's/.*[ ]//'

# 3  
Old 08-06-2012
Code:
awk '$NF ~ /dm-[0-9]/{print $NF}' file

# 4  
Old 08-06-2012
Code:
perl -lane 'if($_=~/dm-21|dm-13|dm-N/){print $F[-1]}' /var/log/messages

# 5  
Old 08-06-2012
It is showing output like this

Quote:
output

dm-2<7><7>kjour
dm-2>kjourna
dm-30
dm-33
dm-4
dm-5
<dm-8
dm-8
<dm-8dm-8
dm-8dm-8
# 6  
Old 08-06-2012
It is showing output like this

which command you tried ?
# 7  
Old 08-06-2012
Quote:
Originally Posted by itkamaraj
Code:
perl -lane 'if($_=~/dm-21|dm-13|dm-N/){print $F[-1]}' /var/log/messages

Not working properly giving only. many characters are missing.

Quote:
output that is total incorrect

<7dm-13
<7dm-21
blocdm-21
ddm-21
<dm-13
dm-13
<dm-1dm-2dm-13
<dm-21
dm-21
dm-dm-21
<m-13dm-13
mdm-21
WRITaljournald(4108)dm-21
WRITE>kjournald(4108)dm-21


as i mentioned i need output like this

Quote:
output

dm-1
dm-2
dm-3
..
dm-11
dm-12
....
dm-22
dm-23
...
dm-33
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with ... matching more than 3 characters

I am trying to understand what the grep command in ubuntu is trying to do here. The contents of my test file is given below harsha@harsha-H67MA-USB3-B3:~/Documents$ cat data abcd efghi jklmno pqr stuv wxyz When I grep for 3 dots (...) without the parenthesis as follows I would expect the... (4 Replies)
Discussion started by: sreeharshasn
4 Replies

2. Shell Programming and Scripting

Grep with special Characters

Need Help For GREP I have a file say g1.txt and content of file is below REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDrives /t REG_DWORD /d 4 /f , REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoClose /t REG_DWORD /d 1 /f ,... (4 Replies)
Discussion started by: jalpasoni
4 Replies

3. UNIX for Dummies Questions & Answers

Is it possible to grep a certain amount of characters?

I have a file similar to the following filler filler filler car 6 mazda filler filler filler filler car civic honda car rav 4 toyota filler filler If i do a "grep -i car file.txt" the output would be car 6 mazda car civic honda car rav 4 toyota however, i want to have the... (4 Replies)
Discussion started by: jl487
4 Replies

4. Shell Programming and Scripting

Grab characters following grep

Hi all, I'm trying to gather data directly following a keyword in a file but I have no guarantee where it will appear in said file so I can't use cut or anything else that assumes it will be located at a certain position. If anyone has any suggestions I'd be grateful. Here is an example of the... (7 Replies)
Discussion started by: Korn0474
7 Replies

5. UNIX for Dummies Questions & Answers

Using GREP for special characters

Hi folks I am issuing the following command: grep "" * Looking for the characters \/:*?"<>|#+%& within all files in a directory, but the command fails being unhappy with pipe: ksh: 0403-057 Syntax error: `|' is not expected. How do I force the command to take the pipe | ? I guess... (2 Replies)
Discussion started by: daveaasmith
2 Replies

6. UNIX for Dummies Questions & Answers

Using grep to find one or more characters

Hi I am a little stuck using grep. I want to be able to find from a file all lines which have the sequence of characters t, followed by any character, followed by the characters ing. I have tried looking at the man pages for help, but did not understand it correctly (as it is not the most... (9 Replies)
Discussion started by: rushhour
9 Replies

7. Shell Programming and Scripting

grep non printable characters

Sometimes obvious things... are not so obvious. I always thought that it was possible to grep non printable characters but not with my GNU grep (5.2.1) version. printf "Hello\tWorld" | grep -l '\t' printf "Hello\tWorld" | grep -l '\x09' printf "Hello\tWorld" | grep -l '\x{09}' None of them... (3 Replies)
Discussion started by: ripat
3 Replies

8. UNIX Desktop Questions & Answers

grep with special characters

Hi there I need to grep for a detail from a file. The pattern to search for involves escape sequences in it. This causes for the problem. grep "P\_SOME\_STRING\_SEARCH" filename Note, I have line like below in the file and expect it to grep. select * from my_system_param ... (3 Replies)
Discussion started by: guruparan18
3 Replies

9. Shell Programming and Scripting

Grep with Special Characters

I need to sort a file, the sort is not a alphabetical sort, it's based on a predefined order which is read from a file called fSortOrder. The format of the fSortOrder file is : STARTPATH" .... .... The file that needs to be sorted is called tmpUnsorted and contains data in the format : ... (6 Replies)
Discussion started by: Vashj
6 Replies

10. UNIX for Dummies Questions & Answers

Grep and extract the characters after

Hi All, I have lines like below in a file A /u/ab/test1.dat A/u/ab/test2.dat A /u/bb/test3.dat A/u/cc/test4.dat I will need /u/ab/test1.dat /u/ab/test2.dat /u/bb/test3.dat /u/cc/test4.dat Pls help Thanks (6 Replies)
Discussion started by: thumsup9
6 Replies
Login or Register to Ask a Question