How to do row comparison in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to do row comparison in shell script
# 1  
Old 09-10-2009
How to do row comparison in shell script

Hi,

I need help on doing the below thing in shell script.

I have a file with millions of rows called "abc.txt". i have another file with millions of rows called "xyz.txt".

I would like to do the below operation.
Open the abc.txt, read the first line, do some operations on the column values and hold it in temp variable. Open the the xyz.txt and read the first line and do some operations on the column values and hold it in temp variables.
Write this temp values to the output file.
The major hiccups in this is i have to compare the first row of abc.txt with the first row of xyz.txt and second row to the second row and so on.

How can i do the comparison of first line with first line and second line with second line and so on ?
# 2  
Old 09-10-2009
if you define 'some operations' we can show you a simple way to do this is awk. It is also possible in bash. But it depends on what the data is like.

We need sample lines from "abc.txt" and samples line from "xyz.txt" - then show us what 'some operations' means.
# 3  
Old 09-10-2009
Let us consider the abc.txt have following lines
20010203000010100000100014716000002968
20010203000010100000100017416000002968
20010203000010100000100017416000002968
20010203000010100000100014716800002968

Let us consider the xy.txt have the following lines
20010230000010100000100014786000002968
20010021000010100000100017486000002968
20010022000010100000100017486000002968
20010203000010100000100014796800002968

I have to read the first line from both the files and
check if the dates (first 8 characters) are same in both the files
if same then i will proceed the fetching of other values.
If dates are not same then quit that record.

Move to second line in both the files and do the process again.

by

Srini
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

2. Shell Programming and Scripting

Korn shell script comparison

I have a scenario to implement in Korn shell script. Here it is.. I need to compare two values to see whether they are same or not. The issue is that the values coming in for comparison can be a string or an integer which can be determined during run time only. Which korn shell comparison... (1 Reply)
Discussion started by: vani123
1 Replies

3. Shell Programming and Scripting

File comparison in shell script

Hi, I have written one script : #!/bin/bash echo -n -e "\nEnter how many files : " read no for (( j=1; j<=$no; j++ )) do echo -n -e "\nEnter $j File name : " read name done for (( j=1; j<=$no; j++ )) do FILE=`find ./ -type f -name "${name}"` echo "$FILE" (3 Replies)
Discussion started by: kiran_j
3 Replies

4. Shell Programming and Scripting

row Comparison

(5 Replies)
Discussion started by: number10
5 Replies

5. Solaris

String Comparison in Shell script

I Have a script which gets the status of oracle database and if the status is READ WRITE ..it should echo "db is up " else "db is down" Here is the code if then echo "db up" else echo "db down" fi done; The script is giving me out put "db down" even thoug the value of... (6 Replies)
Discussion started by: njafri
6 Replies

6. Shell Programming and Scripting

need help in writing a comparison shell script

I have a folder a1 with the following files sample_1.log sample_2.log sample_3.log sample_4.log sample_5.log sample_6.log In another folder there is a file b with the value 5 My script should take the value 5 ( file b), compare it with the files in folder a1, if file name contains... (1 Reply)
Discussion started by: Nagesh1
1 Replies

7. Shell Programming and Scripting

Sequential comparison (one row with file and so on)

Dear linux experts, I'd like to ask for your support, I've read some posts in this forum about files comparison but haven't found what I'm looking for. I need to create a sequential script to compare row-by-row one file with 34 similar files but without success so far. This is what I get: ... (2 Replies)
Discussion started by: Gery
2 Replies

8. Shell Programming and Scripting

bash shell script string comparison

I want to remove a line that has empty string at second field when I use cut with delimeter , like below $cat demo hello, mum hello, #!/bin/sh while read line do if then # remove the current line command goes here fi done < "demo" i got an error message for above... (4 Replies)
Discussion started by: bonosungho
4 Replies

9. Shell Programming and Scripting

consecutive row comparison in awk (?)

hi, I'm totally new to this forum and to awk. I have what I thought was a simple problem, but I can't get anything to work. Here is an example input file: 3.85 4018.4 3.9 4068.4 3.95 4082.9 4 4099.7 # Property:.......etc. 0 4733.3 0.05 4659.7 0.1 4585.6 0.15 4466.2 Two... (2 Replies)
Discussion started by: ogga
2 Replies

10. Shell Programming and Scripting

Help with time comparison shell script for HP-UX

I am using Korne Shell in HP-Ux. Can someone give me and idea on how I can write a shellscript on how to do this please:- On our HP-UX server, a batch file is run every evening at about 6:30pm. The first step of this batch file will touch an empty "flag" file to indicate that the batch has... (6 Replies)
Discussion started by: gummysweets
6 Replies
Login or Register to Ask a Question