one liner to create a value and then search
we add a static number to the pid of the process to name the log file - lets just say 27000.
i spend alot of time adding the two numbers with expr, then cut an paste the number into a grep statements and then search for the number in the log directory. Is there a way i could put it in a one-liner. % i=$(( expr 23416 + 27000 )) ; grep $i ~casper/home/users/logs or is there a way that i could load awk into a variable. % echo 23416 27000 | i=`awk '{ print $1 + $2 }'`| grep $i ~casper/home/users/log |
It took me a minute to figure out exactly what you want; you want to search a log file for "pid+fixed value", right?
Your first line is close to what you want. "$(( ))" is the bash arithmetic operator, and as long as you're adding integers you don't need to use expr or anything like it. I would also turn it around a little, like so. Code:
value="23416" # The pid you want to search You don't need to use $ in front of the variable inside the arithmetic operator. The values will be expanded automatically. Be sure to use double quotes around your grep expression. Single quotes will not allow the operator to work. ----- Edit: waitaminutehere. Reading again more closely, are you perhaps saying you want to search a directory for filenames? For filenames you need to use find instead. Or perhaps grep through the output of ls. Code:
find /logdrectory -name "*$((value+const))*" |
this is great
grep "$((value+const))" ~casper/home/users/logs i am looking for a file in directory - pid + fixed value. i do it maybe fifty times a day, i can't always add it in my head right, and getting sick of using the mouse to cut and paste the value |
you can use awk
Code:
awk 'BEGIN{ |
All times are GMT -5. The time now is 10:21 AM. |