![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk - comparing files | dbrundrett | Shell Programming and Scripting | 4 | 08-22-2008 07:23 AM |
| Comparing two files | guptan | Shell Programming and Scripting | 5 | 08-04-2008 05:02 AM |
| Comparing two files | superstar003 | Forum Support Area for Unregistered Users & Account Problems | 1 | 05-08-2008 12:34 AM |
| Comparing two txt files - pls help | jisha | Shell Programming and Scripting | 5 | 01-23-2008 01:14 AM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-08-2007 11:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Comparing items in 2 files
Hi,
I have 2 files with contents in them and I need to compare each item in each file. File1: item4 item5 File2: item2 item3 item5 item6 The items names can be of different lengths. If the items in the File1 are not in File2, delete the missing item in File1. The resulting File1 in the above example should be: File1: item5 How can I do this using shell script? Thanks in advance! |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
no need of shell script, a command can do...
egrep "$(< file2)" file1 |
|
#3
|
|||
|
|||
|
Hi, thanks for your help but when I tried to use this command, it say syntax error.
I tried using this command instead: egrep "(<file2)" file1 but both the contents in file1 is not changed. Quote:
|
|
#4
|
|||
|
|||
|
$ more file1
item4 item5 hello item2 $ more file2 item2 item3 item5 hello item6 $ egrep "$(<file2)" file1 item5 hello item2 Can you compare the command I have provided and what you typed ?? you are missing "$" symbol... try again. |
|
#5
|
|||
|
|||
|
This is what I get:
% cat file2 item2 item3 item5 item6 % cat file1 item4 item5 % egrep "$(<file2)" file1 Variable syntax I am using unix to do this command |
|
#6
|
|||
|
|||
|
ah got it... you are using csh shell or something similar....
either change your current shell to ksh or write a script as : #!/usr/bin/ksh egrep "$(<file2)" file1 I use ksh shell as my default |
|
#7
|
|||
|
|||
|
hmm.. but I can't test this command in Unix?
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|