Search for a text in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for a text in a file
# 8  
Old 11-10-2008
By the way
it is not only
Wed Nov 9
but

Wed Nov 9 10:10:01 PHT 2008
# 9  
Old 11-10-2008
The extra characters shouldn't matter... but are you sure there aren't 2 spaces between "Nov" and "9"?
# 10  
Old 11-10-2008
Ei got it, thanks.
i used awk '/Wed Nov 9*/
# 11  
Old 11-10-2008
Got problem,
If i try it on my script. See below For example.

Thu Nov 6 18:20:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 7273024 294324 8222268 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08

18:20:01 CPU %user %nice %system %iowait %idle
18:20:02 all 9.00 0.00 0.50 0.00 90.50
18:20:03 all 0.00 0.00 0.25 0.00 99.75
18:20:04 all 0.00 0.00 0.00 0.00 100.00
18:20:05 all 0.00 0.00 0.00 0.00 100.00
18:20:06 all 0.00 0.00 0.25 0.00 99.75
Average: all 1.80 0.00 0.20 0.00 98.00
Thu Nov 6 18:30:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 7273056 294336 8222324 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08

18:30:01 CPU %user %nice %system %iowait %idle
18:30:02 all 8.73 0.00 1.00 0.00 90.27
18:30:03 all 0.00 0.00 0.00 0.00 100.00
18:30:04 all 0.00 0.00 0.00 0.00 100.00
18:30:05 all 0.00 0.00 0.00 0.00 100.00
18:30:06 all 0.25 0.00 0.00 0.00 99.75
Average: all 1.80 0.00 0.20 0.00 98.00

Fri Nov 7 00:30:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 4998120 301544 10456124 0 0 0 2 0 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/07/08

00:30:01 CPU %user %nice %system %iowait %idle
00:30:02 all 8.73 0.00 0.75 0.00 90.52
00:30:03 all 0.00 0.00 0.25 0.00 99.75
00:30:04 all 0.00 0.00 0.00 0.00 100.00
00:30:05 all 0.00 0.00 0.00 0.00 100.00
00:30:06 all 0.00 0.00 0.00 0.00 100.00
Average: all 1.75 0.00 0.20 0.00 98.05

Fri Nov 7 00:40:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 4998136 301556 10456112 0 0 0 2 0 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/07/08

00:40:01 CPU %user %nice %system %iowait %idle
00:40:02 all 8.73 0.00 0.75 0.00 90.52
00:40:03 all 0.00 0.00 0.00 0.00 100.00
00:40:04 all 0.00 0.00 0.00 0.00 100.00
00:40:05 all 0.00 0.00 0.00 0.00 100.00
00:40:06 all 0.00 0.00 0.00 0.00 100.00
Average: all 1.75 0.00 0.15 0.00 98.10


OUTPUT should be:

Thu Nov 6 18:20:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 7273024 294324 8222268 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08

18:20:01 CPU %user %nice %system %iowait %idle
18:20:02 all 9.00 0.00 0.50 0.00 90.50
18:20:03 all 0.00 0.00 0.25 0.00 99.75
18:20:04 all 0.00 0.00 0.00 0.00 100.00
18:20:05 all 0.00 0.00 0.00 0.00 100.00
18:20:06 all 0.00 0.00 0.25 0.00 99.75
Average: all 1.80 0.00 0.20 0.00 98.00
Thu Nov 6 18:30:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 7273056 294336 8222324 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08

18:30:01 CPU %user %nice %system %iowait %idle
18:30:02 all 8.73 0.00 1.00 0.00 90.27
18:30:03 all 0.00 0.00 0.00 0.00 100.00
18:30:04 all 0.00 0.00 0.00 0.00 100.00
18:30:05 all 0.00 0.00 0.00 0.00 100.00
18:30:06 all 0.25 0.00 0.00 0.00 99.75
Average: all 1.80 0.00 0.20 0.00 98.00


Not :

Thu Nov 6 18:20:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 7273024 294324 8222268 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08

Thu Nov 6 18:30:01 PHT 2008

vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 7273056 294336 8222324 0 0 0 1 1 1 0 0 100 0

sar
Linux 2.6.9-67.ELsmp (server1) 11/06/08
# 12  
Old 11-10-2008
It does help when you provide the actual data.

Try this:

Code:
awk '/Thu Nov 6/,/Fri Nov 7/ { if (f) print p; p=$0; f=1 }' inputfile > outputfile

# 13  
Old 11-10-2008
Quote:
Originally Posted by kenshinhimura
yup no output or empty file

On any UNIX-type system, that command would have created an ouput file, even if it was empty.

You must have made at least one mistake in transcribing the script provided; maybe there were more.
# 14  
Old 11-11-2008
thanks Annihilannic got it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a text and return the text from file

Hi I have a set of input strings in a pattern as given below string1 string2 string3 string4 string5 I need to search this sequence of strings from a file in such a way that the first two strings (string1 and string2) and last two strings (string4 and string5) should match with the... (8 Replies)
Discussion started by: my_Perl
8 Replies

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

3. Shell Programming and Scripting

Search text file

awk -F "" ' $2 ~ /<Clinical features:>|<Clinical features:>|<Inheritance pattern:>|<Inheritance pattern:>/{print $2, $3}' OFS='\t' genedx156.txt > output.txt The above command seems to run but no results are in the output. Basically, I am just searching for those key words and output the... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. Shell Programming and Scripting

Search value in text file

Hi, I have the follwoing text file : db1;unrecoverable;0;20110728162548 db1;unrefreshed;1,NO_MV_VIEWS;20110728162548 xe1;Database;1;20110728162548 xe1;autoextensible;0;20110511112053 xe1;chk_offline_dbf;0;20110511112053 xe1;expiry_date;0;20110511112053 xe1;job;4;20110420111823... (2 Replies)
Discussion started by: yoavbe
2 Replies

5. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: address@domen.com (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

6. Shell Programming and Scripting

How do I search on a text file?

Hi, I'm new to shell programming and I have a text file with data with looks like this: chocolate:toblerone swiss:23:100:20 chocolate:ferro rocher:30:90:80 gummi bear:gummi co:5:20:12 . It is basically a file which stores food. The 1st field is the type of food, 2nd... (4 Replies)
Discussion started by: mofako
4 Replies

7. Shell Programming and Scripting

How to Search for text in a file

I need to search for a record in a file and spit out the first record. The file however is csv and is laid out like this: 20984498494 J SMITH MISS SMITH ADDRESSSXXXXXX 30000000000 0000000000000 000000000000000 0000000000 402XXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXX 50XXXXXX ... (12 Replies)
Discussion started by: Pablo_beezo
12 Replies

8. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

9. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

10. UNIX for Dummies Questions & Answers

Search file contain some text

I am loging as root right now. I like to search and find the file that contain the text of "NBC 10.5" Both string and number. I know I need to use grep, but how do I use it??? Oh, yeah if I do, grep 'NBC' * then it gives me error grep: can't open usage i thought root can open... (5 Replies)
Discussion started by: yuimyt
5 Replies
Login or Register to Ask a Question