Problem with grep command options in Sunsolaris


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Problem with grep command options in Sunsolaris
# 1  
Old 12-08-2009
Problem with grep command options in Sunsolaris

Hi Experts

I need the following output from grep command of Sunsolaris on a set of input files.

Output:........
1st search string from file1
2nd search string from file1
3rd search string from file1
1st search string from file2
2nd search string from file2
3rd search string from file2
1st search string from file3
2nd search string from file3
3rd search string from file3 and so on from the last file.

I mean here I need the first 3 lines from each file which matches with the keyword of grep.

Incase if awk or sed command(s) can do the same, please provide that script also.

Thanks in advance...
Sidda
# 2  
Old 12-08-2009
one way:
Code:
for i in file*
do
   grep 'pattern' $file | head -3
done > resultfile

# 3  
Old 12-08-2009
Hi Jim and all

By mistake I gave a different output in my query post. I am extremely sorry over this.
Actually I need the following output:

file1:1st search string from file1
file1:2nd search string from file1
file1:3rd search string from file1
file2:1st search string from file2
file2:2nd search string from file2
file2:3rd search string from file2
file3:1st search string from file3
file3:2nd search string from file3
file3:3rd search string from file3 and so on from the last file.

i.e. I need the file name name also in the output, this is very crucial for me because my file name is my sample
name.

Thanks
# 4  
Old 12-08-2009
How can this be crucial ...
Looks too much like homework to me. You will learn better by reading the grep manual page than having your work done by other people.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ls command options

Hi, If I want to list files with names containing a certain letter like " a " using just one ls command, is there any way of doing that? Note that it is containing a letter instead of one of the following (starting, ending with a letter or having the letter in between). what I want is to show... (1 Reply)
Discussion started by: AAAnni
1 Replies

2. Shell Programming and Scripting

Help executing command with options

Hi, I have this command in a shell script and I can get it to echo ok, but when I try to execute the command I get a "file not found" error. Which is strange because, if I copy and paste the same command at the cli it works ok. What am I doing wrong please? (16 Replies)
Discussion started by: bbbngowc
16 Replies

3. Shell Programming and Scripting

Problem with Grep command

Hi All, Below is my issue. File consist of the 2 server information. This information I am pulling from Netezza table and keeping it in tmp file. File format: database name|schemaname|server number eg: test1.tmp FWKD|FWKD_DEV|1 FWKD1|FWKD_QA|2 my requirement is to fetch the one... (7 Replies)
Discussion started by: bbc17484
7 Replies

4. Solaris

grep options in solaris

Hi, I am interested in knowing the grep optiojs availabel in solaris box, to get the grep results in one line from the log files. only the matched values need to be displayed. I need ot find the values in a message where the search values will be in separate lines of the input. like:... (10 Replies)
Discussion started by: sudha143
10 Replies

5. UNIX for Dummies Questions & Answers

Exploring the grep options

Hi Folks, I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search <ProgramId>627857272120951075</ProgramId> Then I have to open abc.log cd /var/log/ ls -ltr vi abc.log... (4 Replies)
Discussion started by: SankalpS
4 Replies

6. UNIX for Dummies Questions & Answers

Grep Options

Hi Folks, I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search <ProgramId>627857272120951075</ProgramId> Then I have to open abc.log cd /var/log/ ls -ltr vi abc.log... (1 Reply)
Discussion started by: SankalpS
1 Replies

7. Shell Programming and Scripting

Reading command options one by one

Hi, Just some questions on the script below...? Given: bash-2.03$ command -a option1 name1 name2 ParseOptions() { local Len=${#@} local Ctr=2 #always start at 2 local Name=() local Iter=0 while ; do if <- Is this correct? so I can get the $2... (2 Replies)
Discussion started by: h0ujun
2 Replies

8. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

9. Shell Programming and Scripting

Grep options

Hi Team, I have a list of 12000 files and i am need to search for the names of the file which has long version numbers (say more than 5 decimals).. With the below instance u~15.1.4.1.2.1.5.1.5.1.24.1.24.1.5 lk-l~22.1.3.1.9.1.7.1.24.1.23 YDFVALLN.CPY~1 YEUPCASE.CPY~1 YFPRSTID.CPY~1... (2 Replies)
Discussion started by: ganga.dharan
2 Replies

10. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies
Login or Register to Ask a Question