Search file or log for words or strings


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search file or log for words or strings
# 8  
Old 11-11-2012
Got it.Smilie My bad.Smilie
# 9  
Old 11-11-2012
Quote:
Originally Posted by rdrtx1
try also:
Code:
awk -v sw="cat|dog|monkey|bananas|bike" '
BEGIN { c=split(sw,a,"[|]"); }
{ for (w in a) { if ($0 ~ a[w]) d[a[w]]++; } }
END { for (i in a) { o=o (a[i]"="d[a[i]]","); }
  sub(",$","",o); print o;
}' logfile

for some reason, this isn't working for me. i tried it on the messages file.

Code:
awk -v sw="SSL_connect|Untrusted" '
BEGIN { c=split(sw,a,"[|]"); }
{ for (w in a) { if ($0 ~ a[w]) d[a[w]]++; } }
END { for (i in a) { o=o (a[i]"="d[a[i]]","); }
  sub(",$","",o); print o;
}' /var/log/messages

i get this:

Code:
SSL_connect=,Untrusted=

# 10  
Old 11-11-2012
fixed. try:
Code:
awk -v sw="SSL_connect|Untrusted" '
BEGIN { c=split(sw,a,"[|]"); }
{ for (w in a) { if ($0 ~ a[w]) d[a[w]]++; } }
END { for (i in a) { o=o (a[i]"="(d[a[i]]?d[a[i]]:0)","); }
  sub(",*$","",o); print o;
}' /var/log/messages


Last edited by rdrtx1; 11-11-2012 at 09:43 PM.. Reason: fixed for no lines found.
This User Gave Thanks to rdrtx1 For This Post:
# 11  
Old 11-11-2012
You can also try something like this..

Code:
egrep -o "cat|dog|man"  file | sort | uniq -c | paste -sd,

This User Gave Thanks to pamu For This Post:
# 12  
Old 11-11-2012
Hi,

I have a text file called input.txt with below text.

ALLIANZ GLOBAL INV<S><S><S><S> ESTORS US HIGH YIELD FUND AM INC HKD
NEW MEDIA GROUP HOLDINGS LIMITED 70<S><S><S><S><S><S> 8HK
CELSIUS GLOBAL COMMODITIES DELTA FU<S><S><S><S><S> ND B USD

<S>= N Number of Spaces.


I need to exclude the more than one space in my text and need the below output in another file.

ALLIANZ GLOBAL INVESTORS US HIGH YIELD FUND AM INC HKD
NEW MEDIA GROUP HOLDINGS LIMITED 708HK
CELSIUS GLOBAL COMMODITIES DELTA FUND B USD

Please help me as i am struggling to find the above logic.

Thanks in advance

Manish
# 13  
Old 11-11-2012
This should be in a new thread. But try:
Code:
sed 's/   *//g' input.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search the multiple strings in app server.log?

Hi Team, Could you please suggest the below requirement. using the below server log, i just want only the order_id with combination of customer name , error code value as 5000111 & amount value using the shell script i tired using the command grep "error_code>50001111"... (6 Replies)
Discussion started by: venkat918
6 Replies

2. Shell Programming and Scripting

Search and repllace of strings with space between words

Dear all, I have gone through all the search and replace requests but none of them meet my particular need. I have a huge file in which all Unicode characters are stored as Names. A sample is given below. I want to replace strings in that file with a mapper from another file termed as master.dic. ... (4 Replies)
Discussion started by: gimley
4 Replies

3. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Search for words NOT in a text file

I have a long list of alphanumberic words (no spaces or characters) in file1.txt I need to check for the existance of each of the words from file1.txt against file2.txt and if the word is NOT in file2.txt, I need to know about it, either standard output or redirect to file3.txt For example:... (5 Replies)
Discussion started by: ajp7701
5 Replies

6. Red Hat

monitoring search strings /var/log/messages

Hello Everyone, I am setting up monitoring system for linux server, I need to add few some common error message in monitoring file which can search those strings in /var/log/messages file on the client. can someone suggest few error messages. Thanks, (2 Replies)
Discussion started by: bobby320
2 Replies

7. Shell Programming and Scripting

How to search and append words in a file

Hi , I have a file myhost.txt which contains below, 127.0.0.1 localhost 1.17.1.5 atrpx958 11.17.10.11 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958 only in... (2 Replies)
Discussion started by: gsreeni
2 Replies

8. UNIX for Dummies Questions & Answers

search words in different file

Hi, I have 1 - 100 file I want the list of such file which contains word 'internet' Please provide command to do this (3 Replies)
Discussion started by: kaushik02018
3 Replies

9. UNIX for Dummies Questions & Answers

Search File for Specific Words

I have a file that contains the following: Mon Dec 3 15:52:57 PST 2o007: FAILED TO PROCESSED FILE 200712030790881200.TXT - exit code=107 Tue Dec 4 09:08:57 PST 2007: FAILED TO PROCESSED FILE 200712030790879200a.TXT - exit code=107 This file also has a lot more stuff since it is a log file.... (2 Replies)
Discussion started by: mevasquez
2 Replies

10. Shell Programming and Scripting

search for words in file

hi all, i would like to search in a directory. all files they were found shoul be opend and looked about a keyword. if keyword is found i want to see the name of the file. i've rtfm of find and have a command like this : find /etc -exec cat \{}\ | grep KEYWORD but don't work, and : find... (4 Replies)
Discussion started by: Agent_Orange
4 Replies
Login or Register to Ask a Question