I am new to shell programming, and Unix development overall.
I have a following text file with the following contents:
..
Sunny
Monday: x
Tuesday: x
Wednesday: x
Thursday: x
Friday: x
Cloudy
Monday: x
Tuesday: x
Wednesday: x
Thursday: x
Friday: x
Precipitation
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.
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'".
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:
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?
dear Zazzybob
my sed is a little on the rusty side:
could you please clarify a little.....
/precipitation/,/^[^:]$/
" /^[^:]$/" ? (confused!)
also how does the curly bracket play into the syntax..
if you could give an example using curly brackets I would appreciate it..
this is as far as I go with curly brackets and sed..
ex,. sed -e '/foo/{ h; d; }' -e 'N{g}'
other wise i don't know how to apply it the way you did..
moxxx68
ps. I know its a little off the subject but maybe both I and the poster could learn from an example..
This says find anything between the word Precipitation, and the first line that doesn't contain a colon (therefore, this allows us to grab just the "Precipitation" block plus the next header). Then, the curly braces allow us to group together any commands we want sed to execute when the condition is met. I suppose you could analogise this with awks pattern/action behaviour. So all I want to do is print the line(s) that contain "Wednesday". I have formed the script to allow for a little bit of "free-form" within the file. With some of the examples given in this thread, they rely on a rigid and strict file format.