Shell program in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell program in unix
# 1  
Old 02-13-2008
Shell program in unix

Hi,

Iam having the following situation:

Iam reading one file and taking that line one by one and searching that word in file2 using grep command

read_file1()
{
cat file1| while read line
do
grep $line file2 >> outputfile.dat
done
}

now iam having file 1
q
q
a
s
d

file2
q
q
q
a
s
d

Iam reading file1 and greping that word in file2

Now iam getting duplicates in output file , when iam grepping the same word in file1 multiple times from file2. so how can i avoid this??


Can anybody help??
nivas
# 2  
Old 02-13-2008
Quote:
Originally Posted by nivas
Hi,

Now iam getting duplicates in output file , when iam grepping the same word in file1 multiple times from file2. so how can i avoid this??


Can anybody help??
append "| head -1" to your grep.
# 3  
Old 02-13-2008
Why not remove the duplicates from file1 if that's permitted ?

Code:
sort file1 | uniq | while read line

# 4  
Old 02-13-2008
how we can append???

i triyed this
grep $line old_extract.dat append | head -1 > outputfile

This doesn't worked.
nivas
# 5  
Old 02-13-2008
Code:
fgrep -f file1 file2

# 6  
Old 02-13-2008
No . this frep is also not working
nivas
# 7  
Old 02-13-2008
Could you post the output you get and the output you want,
given the data you posted above?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to execute a unix shell script from a java program

Hi All, well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this... Please see the below details...and read the details carefully. I have written some code, logic is 1)from... (4 Replies)
Discussion started by: aish11
4 Replies

2. Homework & Coursework Questions

Shell program in C

Hi all, I have an assignment from school to write a shell program in linux. the idea is to exercise fork() and execv() functions.. the shell program is supposed to be the master and every command that the user prints will run in a new process. we also need to try running the command in every... (1 Reply)
Discussion started by: r3vive
1 Replies

3. UNIX for Dummies Questions & Answers

Unix shell program that reverse a string...

Thanks so much vivekraj (0 Replies)
Discussion started by: andrew1400
0 Replies

4. Shell Programming and Scripting

Shell Program , need help!!

Hi all, I am trying to get a file from an ftp server and i have the list of files which needs to be get from the ftp server. grep unix_prg*.* log.txt > log1.txt log1.txt (which has the list of files) 06-29-09 00:00AM 3550258 unix_prg090629 06-28-09 07:00PM ... (7 Replies)
Discussion started by: raghav1982
7 Replies

5. Shell Programming and Scripting

Shell program in unix

Hi, Iam having file 1 and file 2 as follows: file1 file2 a a a b a c b c I want to get an output file which contains a a (4 Replies)
Discussion started by: nivas
4 Replies

6. Programming

Returning Strings from C program to Unix shell script

Hi, I'm having a requirement where I need to call a C program from a shell script and return the value from the C program to shell script. I refered a thread in this forum. But using that command in the code, it is throwing an error clear_text_password=$(get_password) Error: bash:... (24 Replies)
Discussion started by: venkatesh_sasi
24 Replies

7. Shell Programming and Scripting

help with shell program

I want to print the value of variables a1, a2, a3 in for loop in the following program: a1=this a2=is a3=printed for((i=1;i<4;i++)) do var=a$i #w=`echo $var` e=${var} echo $e done But actually I get a1,a2,a3 as the output not the "this is printed" So the main question is if I... (3 Replies)
Discussion started by: adgarg
3 Replies

8. Programming

Returning Strings from C program to Unix shell script

Hi, Iam calling a C program from a Unix shell script. The (C) program reads encrypted username/password from a text file , decrypts and returns the decrypted string. Is there any way i can return the decrypted string to Unix shell program. My shell script uses the output of the program to... (11 Replies)
Discussion started by: satguyz
11 Replies

9. Shell Programming and Scripting

shell program

How to write a shell script which takes 3 strings as positional parameters,first and second are file names and third is a directory.if the two files exist in `pwd` and they contain a specific pattern and their size is greater than 32 bytes,moves these files into directory? (1 Reply)
Discussion started by: rameshparsa
1 Replies

10. Shell Programming and Scripting

ftp files from Unix to Windows through shell program

Hi, I made a shell script to allow user to ftp file to windows shared drive. Here is part of my code within my shell script: /usr/bin/ftpmtc $usr $pswd $jobno Within 'ftpmtc': #ARGUMENT: USER,PASWD,JOBNO,VER,LOG_DATE,$$ $UCB/echo "user $1 $2" > $inst_file $UCB/echo "cd prod" >> $inst_file... (7 Replies)
Discussion started by: whatisthis
7 Replies
Login or Register to Ask a Question