single line command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting single line command
# 1  
Old 02-07-2007
single line command

i need to search for a single pattern in three different logs....what would be the best one line script????
# 2  
Old 02-07-2007
Code:
grep "pattern" log1 log2 log3

# 3  
Old 02-07-2007
but i want to differentiate results got from each of the logs...the above command will display all the results in one screen :-(

eg:
log1
results
log2
results
log3
results
# 4  
Old 02-07-2007
you have the results differentiated with the output of grep itself

Code:
grep pattern l1 l2 l3

Code:
l1: pattern
l2: pattern
l3: pattern

# 5  
Old 02-07-2007
Code:
grep "pattern" log1 log2 log3 | 
awk -F: ' { if ( file != $1 ) { file=$1; print file } sub(/^[^:]*:/,"",$0);print $0 } '

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

2. Shell Programming and Scripting

Su and run single line command

myenv.sh script sets LOG_DIR variable. I can run the script and echo the variable in a single line as: # First set LOG_DIR to some dummy 'NONE' value $ export LOG_DIR="NONE" $ echo ${LOG_DIR} NONE $ cat /tmp/bin/myenv.sh export LOG_DIR="/tmp/log" #The below command doesn't show the... (2 Replies)
Discussion started by: ysrini
2 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Running Two scripts in a single command line

Hi All, I have two scripts which i want to run in a single command line(or in a single script). And if both the scripts in the main script fail then i want to pass a value to a Application specific utility which will trigger some alert.The value can be anything. Somebody please help.It is... (1 Reply)
Discussion started by: shroh
1 Replies

5. UNIX for Advanced & Expert Users

Issuing a Here Document as a Single Line Command

How can I run a here document on just one line? I ask, because I need to issue it from C++ as a system() or similar command and for security reasons I don't want to write out a shell script file from the program and run it. For example, how could I write: passwd test <<EOF n3wp3ss... (3 Replies)
Discussion started by: BrandonShw
3 Replies

6. Shell Programming and Scripting

a few single line command

i m trying to find the answers of a past year exam questions , i m sure it ll be very easy for u guys , this is not a hw assignment or somth. i just wanna be sure of right answers . write a single instruction to perform each of the following tasks: (u r allowed to use c shell, and u can use... (2 Replies)
Discussion started by: brhn
2 Replies

7. UNIX for Advanced & Expert Users

Merging two command into single line

1. du -sch int* | grep "total" | awk '{print $1}' first command result is 17K 2. echo "B" Result B i want the output is 17KB (2 Replies)
Discussion started by: kingganesh04
2 Replies

8. AIX

ls command output in single line

Hi, Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)? I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands? Thanks for your help Sheshadri (7 Replies)
Discussion started by: arsheshadri
7 Replies

9. Shell Programming and Scripting

Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place?... (1 Reply)
Discussion started by: gator76
1 Replies

10. UNIX for Dummies Questions & Answers

run command Unix on a single line

Hi everybody.. I need to enter in bash mode and then run a command and this just in a single command line. I tried : "bash ^M| somecommand" but nothing.. How do I do to simulate the return button just right after the bash command ? Thanks.. (8 Replies)
Discussion started by: Riddick61
8 Replies
Login or Register to Ask a Question