JohnLucania
asked on
Find strings from history
I am trying to find commands for 'history' containing 'gcc.4.1.1.tar'.
for i in `cut -d: -f6 /etc/passwd`
do
if [ -f "$i/.sh_history" ]
then
echo "$i/.sh_history"
grep "^gcc.4.1.1.tar" "$i/.sh_history"
fi
done
but, it doesn't return what I need. How to do?
for i in `cut -d: -f6 /etc/passwd`
do
if [ -f "$i/.sh_history" ]
then
echo "$i/.sh_history"
grep "^gcc.4.1.1.tar" "$i/.sh_history"
fi
done
but, it doesn't return what I need. How to do?
ASKER
It returns:
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
/home/oracle/.sh_history
grep: 0652-033 Cannot open /home/oracle/.sh_history.
/home/d_prod/.sh_history
grep "gcc.4.1.1.tar" "$i/.sh_history"
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
//.sh_history
grep: 0652-033 Cannot open //.sh_history.
/home/oracle/.sh_history
grep: 0652-033 Cannot open /home/oracle/.sh_history.
/home/d_prod/.sh_history
grep "gcc.4.1.1.tar" "$i/.sh_history"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The "^" in the regular expression means beginning-of-the-line. As "gcc.4.1.1.tar" is not
something usually typed at the beginning of a command, maybe there it is the mistake.
Try then:
for i in `cut -d: -f6 /etc/passwd`
do
if [ -f "$i/.sh_history" ]
then
echo "$i/.sh_history"
grep "gcc.4.1.1.tar" "$i/.sh_history"
fi
done
Rgds