Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

noob sorting question 1

Status
Not open for further replies.

Nostradamus

Technical User
May 3, 2000
419
SE
I want to do the following.

run a command and sort the output.
Before I receive the output the command itself requires me to hit enter two times. Obviously I want to automate this.
The output then looks something like this.

1 2 3 4 5

value1 value2 value3 value4 value5
value1 value2 value3 value4 value5
value1 value2 value3 value4 value5

I want to search column 4 for a value that is 50000 or less.
I also want to skip the first 2 lines of the output, thus sorting out the 1 2 3 4 5 line.
Also, if the value in column 4 is 50 000 or less I want it to email me about it.

I've tried searching for a sollution but without luck. I think I have an idea of how to email myself and perhaps using awk, sed to sort out the column. However I can't manage to get it all to work.

Hope you understand what I mean and want to accomplish.

Thanks a lot in advance

/Sören
 
Hi

Where is the sorting there ?
Code:
[gray]# search[/gray]
awk 'NR>2&&$4<=50000' /input/file

[gray]# send the search result[/gray]
awk 'NR>2&&$4<=50000' /input/file | mail person@example.com
If you want to send mail only if there such data, you have to buffer the results. Depends on the expected amount of data, if you use a variable or a file.
Code:
[gray]# variable[/gray]
result=$( awk 'NR>2&&$4<=50000' /input/file )
test "$result" && echo "$result" | mail person@example.com

[gray]# file[/gray]
awk 'NR>2&&$4<=50000' /input/file > /tmp/result.txt
test -s /tmp/result.txt && mail person@example.com < /tmp/result.txt

Feherke.
 
sorry, my english isn't what it used to be :)
I don't want to sort, just filter out a certain part of an output/file. in this case column 4.
You are correct in asuming I only want to send the information if the criteria is met. I therefor ran your script using a file instead of a variable and it works like a charm. thanks a lot.

How about the enter characters. The command that gives the output need to receive two of those in order to give me the output.
It's not a file but the output of a command I need to search in. What should I replace /input/file with if I want to search the outcome of a command?

Hope you understand what I mean.

/Sören
 
Hi

The simplest way would be to just pass the the newlines to that command's input :
Code:
(echo; echo) | [green][i]the_command[/i][/green] | awk 'NR>2&&$4<=50000' > /tmp/result.txt
If does not work, tell us more about that command. But probably you will need to use [tt]expect[/tt].

Feherke.
 
I managed to solve the problem by using a different command to get the output. By using this method I don't have to enter 'enter' before I receieve the output.

Thanks a lot for your help.

/Sören
 
Soren - for completeness it would be good to know which 'different command' you used.

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
I don't think you're gonna get much more wiser but here goes.
It's a command to get output from a caché database

I first used
cache -U '%SYS' 'ALL^%FREECNT'; Prompt;
which made me hit 'enter' two times before showing me results.

I later ran
echo -e 'd ALL^%FREECNT\n\n\nh'|cache

/Sören
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top