Combining elements of different commands in history


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combining elements of different commands in history
# 1  
Old 10-22-2003
Question Combining elements of different commands in history

What is the correct format for a single command that would combine portions of 2 different lines in the command history? I'm using a C shell. Here's a simplified command history to clarify:

4 rm file1
5 ls -ld file2 file3 file4
6 cat file 5


With the above history, what would be the command to remove the files called file3 and file 5 using only history references and word identifiers? Here is what I was trying:

!4 5:2 6:1

...didn't work. I'm getting frustrated with having to repeatedly enter long pathnames, etc.

Thanks in advance for any help,
-Dbyte
# 2  
Old 10-22-2003
why dont you create an alias?
# 3  
Old 10-22-2003
Im not aware of most folks using C shell for normal admin work, although some do use it I am sure.

Most use ksh or sh or posix for HPUX.... I know that these have history functionality... works very well... Esc k works to scroll up thru commands and execute them and I also have autocomplete for long filenames, very handy.
# 4  
Old 10-22-2003
In reply:
Optimus_P - My question doesn't relate to any single command. I gave the sample only for clarification. I don't want to create an alias for each & every command that I might ever need in reference to the question. That would be way too much work (& require too much forsight) for a newbie like me! I was hoping that if I could get this question answered then this method would be simpler & less time consuming in the long run. I do love aliases though!

Kelum_Magnus - For better or worse C shell is where I'm at. My knowledge is minimal, so I'd rather figure out how to make my existing shell work for me than change it altogether. Again, this seems like a LOT of work to avoid this 1 circumstance. Generally I have been very pleased with the C shell. In fact, this is my 1st time being truly stuck trying to accomplish something in it.

So using the example I gave previously, can someone please show me the command I should be entering? Was I even close with my attempt? I know that this can be done, I just don't know how.

Thanks for your input guys. I do appreciate the insight of seasoned users.
# 5  
Old 10-22-2003
I think that:
!4:0 !5:2 !6:1
will do it.
# 6  
Old 10-22-2003
Brilliant! It worked perfectly. Thanks for your help Perderabo.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining 2 commands

Hello all, I need to send an attachment and text in the body, both in the same Email. Below are two cammand that send the required data in separate Emails. I need to combine them so that I get just 1 Email containing the attachment & text in the body. uuencode ${filename} "${file_}" |... (6 Replies)
Discussion started by: Junaid Subhani
6 Replies

2. Shell Programming and Scripting

How to combining awk commands?

I can achieve two tasks with 2 different awk commands: 1) awk -F";;WORD" '{print $2}' file | sed '/^$/d' #to find surface_word 2) awk -F"bw:|gloss:" '// {print $2}' file | sed '/\//!d; s:/*+*: + :g; s:^+::; s: *+ *$::;' #to find segmentation of surface_word Number 1) finds surface_word... (7 Replies)
Discussion started by: Viernes
7 Replies

3. UNIX for Dummies Questions & Answers

Help with combining the ls and 'file' commands

I have a directory of 3000 files without extensions (Solaris 5.10). I would like to iterate the file names through the 'file' command and output their mime types (most are pdf or jpg, but a very few might be psd or swf which show simply as 'data') So, I would like the output of the 'ls'... (2 Replies)
Discussion started by: pwallace
2 Replies

4. UNIX for Dummies Questions & Answers

How to review the history and the commands that has been done in this history?

Hello every body, Kindly inform me How Do i find out the time I executed a command previously on UNIX Solaris?? To be more specific and more clear about what i want to know is that I want a command the enables me to know the history and which command i run at this history/time. FYI I used... (5 Replies)
Discussion started by: ahmedamer12
5 Replies

5. UNIX for Dummies Questions & Answers

Combining resukts of ls commands

Hi, I have a directory with some XML files in it. I can use wildcards to get the list of XMLs I want say I have following XMLs in same dir Employee1.xml Employee2.xml Employee3.xml and Salary1.xml Salary2.xml Salary3.xml apart from other .txt .dat files etc I want to write a unix... (7 Replies)
Discussion started by: dsrookie
7 Replies

6. UNIX for Dummies Questions & Answers

Combining two commands that use sar.

hey can anyone tell me how can i combine these two commands so that it is executed only once, but gives me both the results. IDLE=`sar 30 6 | grep Average | awk '{print $1 $5}' ` sar 30 120 | awk '{print $1" "$5}' >> mailx -m -s "$MSG" xyz@abc.com. (5 Replies)
Discussion started by: Ankur Khatri
5 Replies

7. Shell Programming and Scripting

Combining multiple commands

Hi Guys, I am looking to optimze these 5 SSH lines to a single SSH to get my machine to not hang! lol! cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} top -b > util/{}.top &' >> r_query_info cat hosts.lst | xargs -n1 -t -i echo 'home/util/timeout 6 0 ssh -q {} uname -r... (5 Replies)
Discussion started by: wick3dsunny
5 Replies

8. UNIX for Advanced & Expert Users

Combining two commands.

Is there anyway to achieve "find /home -name "*.bashrc" 2>/dev/null" and "PS1="\n>"" in the same command? I just wanna add a line to the previous command to change the PS1 variable to ">". (1 Reply)
Discussion started by: raidkridley
1 Replies

9. UNIX for Dummies Questions & Answers

combining commands

Hello all, I am trying to list and count all the files of a particular type in any given directory. I can use the commands separately but when I combine them they do not give an output. The command for counting the files is ls -1 | wc -l and for listing all the file of particular type say... (2 Replies)
Discussion started by: BigTool4u2
2 Replies

10. UNIX for Dummies Questions & Answers

combining sed commands

I would like to change the lines: originalline1 originalline2 to: originalline1new originalline1newline originalline2new originalline2newline To do this, id like to combine the commands: sed 's/^/&new/g' file > newfile1 and sed '/^/ a\\ newline\\ \\ (2 Replies)
Discussion started by: Dave724001
2 Replies
Login or Register to Ask a Question