grep with history command

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep with history command
# 1  
Old 08-08-2011
Question grep with history command


history 800 | grep mail

  387  mailx -s "test from `hostname`"  < /dev/null
  388  mailx -s  -a /tmp/ "test from `hostname`"  < /dev/null
  389  mailx -s  "test from `hostname`"  < /dev/null
  390  mailx -s  "test from `hostname`"  < "Hello"
  392  mailx

Now I need the command in history at position 391, how could I ?

Kindly help.
# 2  
Old 08-08-2011
history 800 | grep 391

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 08-08-2011
history 400 | grep -e '^391'
fc 391 391 # and clear the buffer before exiting

# 4  
Old 08-09-2011

The problem with this is

history 800 | grep 391
It grep for any command that has the string '391' which is not desired.

The problem with the below is

history 400 | grep -e '^391'

I do not have the -e option with my grep.

grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .

SunOS mymachine 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220

fc 391 391 # and clear the buffer before exiting
This works however not sure about "# and clear the buffer before exiting". Can you please explain?
# 5  
Old 08-09-2011
Please try to use this :

history | awk '$1~/72/{print $0}'
This User Gave Thanks to Mani_apr08 For This Post:
# 6  
Old 08-09-2011
You don't need "-e" option for grep. And I think '# and clear the buffer before exiting" it's about clearing of the buffer of an editor. But you can do
history 391 391

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

History command

Hi, I would like to know commands which i have executed on terminal should not be present in the history.How can i approch please help me. Regards, Mastan (1 Reply)
Discussion started by: mastansaheb
1 Replies

2. Shell Programming and Scripting

grep'ing dot history file

Hi, I tried to grep ".sh_history" (DOTsh_history) file and did not return anything though I found the word in .sh _history file through vi editor in Linux. Then I tried to grep ".profile" to check if it is the prob with hidden files and I got results. Then I verified the same with my friend... (4 Replies)
Discussion started by: bobbygsk
4 Replies

3. UNIX for Dummies Questions & Answers

The history command: See other users command history

Can anyone tell this: If two users are logged into the same server from different locations. Is there a way to see the history command of the other user? I tried the history command, but it is showing me only the commands I used. Thanks in advance for your help. Iamnew2solaris (1 Reply)
Discussion started by: iamnew2solaris
1 Replies

4. UNIX for Dummies Questions & Answers

command history

Hi all, How can i view command history of a day. when i used history command in my AIX server, it shows only last 16 commands. Is there a location where all the history is stored ? Thanks in advance! (2 Replies)
Discussion started by: lramsb4u
2 Replies

5. UNIX for Dummies Questions & Answers

using command history

Hi All. Suppose I am in a "verylongpath" directory and I type "gedit thisfile". At a later stage, the command is accessible from the hystory, but it is useless if I have moved to another directory. The same applies to "cd myfolder", etc. Is there a way to instruct shell history to... (1 Reply)
Discussion started by: bruno69
1 Replies

6. UNIX for Dummies Questions & Answers

vi command history

How do you look at the whole list of previous commands you have used in VI? I know you can use the up and down arrows, but I know there's a way to see the full list. (5 Replies)
Discussion started by: cokedude
5 Replies

7. Shell Programming and Scripting

history awk grep sort

can someone help me in the awk part...little confuse on that part. The problem is this: what input each utility gets and what it does with data and what output is provides to the next utility) history | awk '{a++}END{for(i in a){print a " " i}}' | sort -rn | grep '^' Thanks (4 Replies)
Discussion started by: Learnerabc
4 Replies

8. Shell Programming and Scripting

History Command

Hi all experts, I want to see all the command that is typed in the server 3 days ago. I typed HISTORY command but it does not show all the things. The reason is my senior DBA could see all the commands ran in the server 3 days ago but i cannot see. Please let me know is there anyway i can view... (6 Replies)
Discussion started by: ma466
6 Replies

9. Shell Programming and Scripting

need help in history Command

in my system history command is set to 60 how to remove all the command status even if i give history command. i mean: if i give history command in unix it should not show to achieve this (2 Replies)
Discussion started by: ali560045
2 Replies

10. UNIX for Dummies Questions & Answers

Problem with history and grep

okay, i did the command: echo `history` >> /new.txt i got a long line, which due to the size of my screen, it made 3 lines. i then tried the command: grep emacs new.txt while in root and i got a full the same long line any help appreciated (2 Replies)
Discussion started by: cleansing_flame
2 Replies
Login or Register to Ask a Question