comm not working for this case. HELP!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comm not working for this case. HELP!
# 1  
Old 09-13-2007
comm not working for this case. HELP!

I have two sorted files.
newfile has records like:
aaa|bbb|ccc|||
ddd||eee|fff||

oldfile has records like:
aaa|bbb|ccc|
ggg||hhh|fff

The output should like:
ddd||eee|fff||

I use comm but it's not working for this case.
comm -2 -3 newfile oldfile > difffile

The difffile is the same as newfile. How to get the output I want? Could anyone help me?
Thanks in advance!
# 2  
Old 09-14-2007
comm

Your problem is that line one of newfile is *not* the same as line one 0f oldfile.

For your example to work you need to remove trailing '|||..' from all lines

comm's output depends on lines being identical
# 3  
Old 09-14-2007
Quote:
Originally Posted by ajcannon
Your problem is that line one of newfile is *not* the same as line one 0f oldfile.

For your example to work you need to remove trailing '|||..' from all lines

comm's output depends on lines being identical
Yes. I am aware of that. I am thinking of appending '|' at the end of each line of oldfile. But I am stucked at How to count the number of '|' just for the first line?(All lines have the same pipe count) Do you have any idea? Thanks.
# 4  
Old 09-15-2007
Code:
/home/kamitsin>sed -e 's/$/\|\|/' oldfile  > oldfile1
/home/kamitsin>comm -2 -3 newfile oldfile1
ddd||eee|fff||

kamitsin
# 5  
Old 09-15-2007
Quote:
Originally Posted by kamitsin
Code:
/home/kamitsin>sed -e 's/$/\|\|/' oldfile  > oldfile1
/home/kamitsin>comm -2 -3 newfile oldfile1
ddd||eee|fff||

That's just a sample file. In a real world, we don't know how many '|' to append. Is there any way to count the number of the '|' for the first line of the file?(All records have same number of '|'). Thank you for your help!
# 6  
Old 09-16-2007
Hi.

Here is an example:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate counting specific characters.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

version bash tr wc head

# Create data file, from which line 1 will be examined.

cat >data1 <<'EOF'
aaa|bbb|ccc|||
ddd||eee|fff||
EOF

echo
echo " Counting \"|\", expecting 5:"
head -1 data1 |
tr -dc '|' |
wc -c

exit 0

Producing:
Code:
% ./s1

GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
tr (coreutils) 5.2.1
wc (coreutils) 5.2.1
head (coreutils) 5.2.1

 Counting "|", expecting 5:
5

Modify as you need to, see man pages for details ... cheers, drl
# 7  
Old 09-17-2007
Thank you drl!
It works well.
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash read input in case statement not working as expected

I'm having an issue with bash read input when using a case statement. The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here. defaultans=8hrs read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Discussion started by: woodson2
5 Replies

2. UNIX for Beginners Questions & Answers

How to ignore Case with in COMM command?

Hi, How can i ignore case between 2 files in unix using COMM command. 2 input files are: -bash-4.1$ more x2.txt HELLO hi HI raj -bash-4.1$ more x3.txt hello hi raj COMM command: -bash-4.1$ comm x2.txt x3.txt hello HELLO hi (3 Replies)
Discussion started by: raju2016
3 Replies

3. Shell Programming and Scripting

Change first letter of a word from lower case to upper case

Hi all, I am trying to find a way to change first letter in a word from lower case to upper case. It should be done for each first word in text or in paragraph, and also for each word after punctuation like . ; : ! ?I found the following command sed -i 's/\s*./\U&\E/g' $@ filenamebut... (7 Replies)
Discussion started by: georgi58
7 Replies

4. Shell Programming and Scripting

Case statement not working as expected

case "$freq" in " Hz") low=250; high=550;; "8 Hz") low=250; high=1000;; " Hz") low=400; high=1000;; "63 Hz") low=550; high=1000;; " Hz") low=400; high=550;; ... (2 Replies)
Discussion started by: Michael Stora
2 Replies

5. Shell Programming and Scripting

Switch Case not working

My switch case is not working properly. When I press 6 or 'r' it prints out all the names of the project and the error message. #!/bin/bash while true; do read -p "Enter project number (1/2/3/10/20/30):" menu #grabs the informations of the project number and stores it into a menu... (1 Reply)
Discussion started by: Rapcher
1 Replies

6. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

7. Shell Programming and Scripting

comm not working

Hi Sorry if this a repeat question, I have the following two files. Both are sorted. file1 ---- CSCeb69473 CSCsg70355 CSCsj78917 CSCsj85065 CSCsl48743 CSCsl72823 CSCsl77748 file2 ---- CSCsg39295 (7 Replies)
Discussion started by: amitrajvarma
7 Replies

8. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

9. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question