Visit Our UNIX and Linux User Community

finding data in a file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding data in a file
# 1  
Old 12-23-2004
finding data in a file


I am new to shell programming, and Unix development overall.

I have a following text file with the following contents:

Monday: x
Tuesday: x
Wednesday: x
Thursday: x
Friday: x
Monday: x
Tuesday: x
Wednesday: x
Thursday: x
Friday: x
Monday: x
Tuesday: x
Wednesday: 50%
Thursday: x
Friday: x

I need to extract the Precipitation for Wednesday (I just need the 50%). Position of Precipitation is not always the same in the file. I have tried to use grep and awk, but have not been successful so far, probably because I haven't used awk before now.

Does anyone have any ideas? If so, please help.

Thank you in advance,

# 2  
Old 12-23-2004
Hammer & Screwdriver

try something like :
awk -F '{print $2}' input file | grep -v 'x'
should work!!
# 3  
Old 12-23-2004
Thanks for the quick reply. Could you please explain it a little bit more? I do not see where in this command does it say "search for 'precipitation'".
# 4  
Old 12-23-2004
-> Wednesday: 50%
-> Thursday: x

awk -F '{print $2}' input file = recupere the second word (50% and x)

|grep -v 'x' = exlude the character "x"

Also you could used :
awk -F '{print $2}' input file | grep %
you recupere only the %

It is the same result
# 5  
Old 12-23-2004
Yes, that's how I understood it as well. But this doesn't help me with my problem. Xs were there just in place of some other numbers, I don't acutally get Xs in the file I need to parse, so if for example I have:

Monday: 10
Tuesday: 15
Wednesday: 53
Thursday: 57
Friday: 8
Monday: 35
Tuesday: 7
Wednesday: 95
Thursday: 68
Friday: 98
Monday: 15
Tuesday: 29
Wednesday: 50
Thursday: 26
Friday: 1

then the suggested command would return all of the numbers in the second column if I understand this correctly.
The point here is that I need to find the Precipitation category first, and then get data for Wednesday only. Can you help me with that?

Sorry if my first example was confusing.

Thank you.
# 6  
Old 12-23-2004
grep -nA7 'Precipitation' | awk -F '/Wednesday/{print $2)
should work..
or alternately
grep -nA7 'Precipitation' | awk '-F /Wednesday/{print, "Precipitation:" $2)
hope that solves the problem
# 7  
Old 12-23-2004
I'd personally use sed

#!/bin/sed -nf

/Precipitation/,/^[^:]*$/ {

Then invoke with
foo.sed filename_here


Previous Thread | Next Thread
Test Your Knowledge in Computers #169
Difficulty: Easy
Red Hat, Inc. is an Canadian multinational software company.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding Data in the file

Hi All I have a file having columns such as AAA,BBB,CCC,Aug 13 2013 AAA,BBB,CCC,Aug 11 2013 AAA,BBB,CCC,Aug 12 2013 AAA,BBB,CCC,Aug 13 2013 Now I need to extract the records which are not of todays date (Considering Today date is 13-Aug-2013 So I should get below records... (10 Replies)
Discussion started by: Prashantckc
10 Replies

2. UNIX for Dummies Questions & Answers

Finding data value that contains x% of points

Hi, I need help on finding the value of my data that encompasses certain percentage of my total data points (n). Attached is an example of my data, n=30. What I want to do is for instance is find the minimum threshold that still encompasses 60% (n=18), 70% (n=21) and 80% (n=24). manually to... (4 Replies)
Discussion started by: ida1215
4 Replies

3. Shell Programming and Scripting

Finding data in large no. of files

I need to find some data in a large no. of files. The data is in the following format : VALUE A VALUE B VALUE C VALUE D 10 4 65 1 12 4.5 65.5 2 10.75 5.1 ... (2 Replies)
Discussion started by: cooker97
2 Replies

4. Shell Programming and Scripting

Finding standard deviation for all columns in a data file

Hi All, I want someone to modify the below script from this forum so that it can be used for all columns in the file( instead of only printing column 3 mean and standard deviation values). I don't know how to loop around all the columns. ... (3 Replies)
Discussion started by: ks_reddy
3 Replies

5. HP-UX

finding these, whether previous data stored ?

Hi All, On HP Unix, 11.23 can following be checked , Processes which were consuming more 1)CPU 2)Memory 3)page faults For particular Time Frame say Yesterday 7 Am to 7.30 Am and , Yesterday Evening 19.00 Pm to 19.30 Pm Please specify how. whether we need to enable, some... (6 Replies)
Discussion started by: sidharthmellam
6 Replies

6. Shell Programming and Scripting

Parsing chunks of text and finding data

Hi, I need a script that parses and greps data out of a textfile. I have a text file that has this structure: File1 host1.localdomain text random text Found errors this text is random (41123) --- random random at.5165 ---- random random at.5165 ---- random random at.5165 ----... (2 Replies)
Discussion started by: erick_tuk
2 Replies

7. Shell Programming and Scripting

Finding Minimum value per Row range of data

Here is an example of a file I am working with: C 4704 CB 1318 ASP 115 BGRF 1 weak 0.0% 4.33 C 4720 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.71 O 4723 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.48 O 4723 CG 1321 ASP 115 BGRF 1 weak 0.0% 4.34... (3 Replies)
Discussion started by: userix
3 Replies

8. Shell Programming and Scripting

Finding Overlap between two sets of data

Hi everyone, I posted this earlier, but the idea changed since then and I figured it would make more sense if I repost with a clearer idea in hopes someone can help me out. I have two lists of data in file1 and file 2 file1 (tab separated - column1 column2 column 3) 1 91625106 ... (1 Reply)
Discussion started by: labrazil
1 Replies

9. Shell Programming and Scripting

finding null records in data file

I am having a "|" delimited flat file and I have to pick up all the records with the 2nd field having null value. Please suggest. (3 Replies)
Discussion started by: dsravan
3 Replies

10. Shell Programming and Scripting

Finding duplicate data in a file

A pogram named LOGGEDON returns an output of: Ref_num IP Address Logged on User 12000 12-02-2002 11:00 john 12004 12-03-2002 14:00 mary 12012 12-03-2002 11:30 bob 12024 ... (1 Reply)
Discussion started by: dinplant
1 Replies

Featured Tech Videos