File comparison problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File comparison problems
# 1  
Old 07-03-2018
File comparison problems

We are running parallel reports with Legacy vs a new system and want to compare certain lines with the diff or diff -b command. When a six digit number is read at the beginning of the line (no decimal point) we read and ignore a header line (next), move any minus sign to the end of the number and, if the next line starts with "Today", a line with the six digit number, a "|" symbol and the rest of the line is created. This is the sed script we use:
Code:
/^[0-9][0-9][0-9][0-9][0-9][0-9][^\.]/{
     N
     s/\n.*//
     N
     s/\n/|/
     s/-\([\.0-9]*\)/\1-/g
     /Today/p
     }

If there was no business done, the new system replaces 0.00 twice with a line break. We need to change:
Code:
Today 0 0.00 0.00 0.00 0.00
0.00
0.00 0.00 -2236.93

----------------- to ------------------

Today 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 -2236.93

Can this be done with the above script or do I need to fix it with an earlier step?

TIA
# 2  
Old 07-03-2018
Can you post a sample of your source file?
# 3  
Old 07-03-2018
When business is done, the line starting with "Today" will be followed by a count and ten two-digit numbers (percents or dollar amounts)--my problem is when the count is zero and certain 0.00 are replaced with a new line.

This is what the set of data looks like:
Code:
123456
Constant column headings are on this line and will be ignored
Today 0 0.00 0.00   ... etc

-------------- output ----------------
123456 |Today 0 0.00 0.00 0.00   etc -2236.93

I have been experimenting with this sed script as a new first step:
Code:
/^Today 0 0.00 / { N
                   N
                   s/\n/0.00 /g
                 }

Thanks for looking at it.
# 4  
Old 07-03-2018
Your data sample show a first line with 6 digits, whereas your sed script in post#1 tests for 6 digits followed by any character that is neither . or a \ . So the script will not match the first line of your data sample.

Could you post a more accurate sample?
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 07-03-2018
The "\" was to escape the decimal point so I wanted six digits not followed by a decimal point. That got rid of my false positive using SCO Unix. Six digits with nothing else on the line was the only thing I was interested in.
# 6  
Old 07-03-2018
Hi, OK.

So to match 6 digits on a line only, try:
Code:
/^[0-9]\{6\}$/{

Also note that a \ inside square brackets denotes a literal \ character, not an escape.

Last edited by Scrutinizer; 07-03-2018 at 11:40 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 7  
Old 07-05-2018
Quote:
Originally Posted by Scrutinizer
So to match 6 digits on a line only, try:
Code:
/^[0-9]\{6\}$/{

Also note that a \ inside square brackets denotes a literal \ character, not an escape.
That didn't fly the first time but then I discovered a trailing space after all the valid six digit numbers, so adding a space before the $ fixed it.

I didn't realize a period didn't need to be escaped when in a bracket. In the first code in my OP on the last s command (ends with /g), I took out the "\" with no ill effects.

Again thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Comparison

HI, I have two files and contains many Fields with | (pipe) delimitor, wanted to compare both the files and get only unmatched perticular fields. this i wanted to use in shell scriting. ex: first.txt 111 |abc| 230| hbc231 |bbb |210 |bbd405 |ghc |555 |cgv second.txt 111 |abc |230 |hbc231... (1 Reply)
Discussion started by: prawinmca
1 Replies

2. Shell Programming and Scripting

File Comparison: Print Lines not present in another file

Hi, I have fileA.txt like this. B01B02 D0011718 B01B03 D0012540 B01B04 D0006145 B01B05 D0004815 B01B06 D0012069 B01B07 D0004064 B01B08 D0011988 B01B09 D0012071 B01B10 D0005596 B01B11 D0011351 B01B12 D0004814 B01C01 D0011804 I want to compare this against another file (fileB.txt)... (3 Replies)
Discussion started by: genehunter
3 Replies

3. Shell Programming and Scripting

file comparison

Dear All, I would really appreciate if you can help me to resolve this file comparison I have two files: file1: chr start end ID gene_name chr1 2020 3030 1 test1 chr1 900 5000 2 test1 chr2 5000 8000 3 test2 chr3 6000 12000 4 test3 chr3 6000 15000 5 test3 file2:... (2 Replies)
Discussion started by: paolo.kunder
2 Replies

4. Shell Programming and Scripting

String comparison problems

Req: =========== 1)I have one shell script a.sh 2)I opened Putty session , with user name = SIR100 , and i ran a.sh script in back ground and it took 5 minutes to complete.Meanwhile,i ran same script second time i.e a.sh with same user it sholud not allow to run the script , but it's... (3 Replies)
Discussion started by: as234301
3 Replies

5. Shell Programming and Scripting

Help with file comparison

Hello, I am trying to compare 2 files and get only the new lines as output. Note that new lines can be anywhere in the file and not necessarily at the bottom of the file. I have made the following progress so far. /home/aa>cat old.txt 0001 732 A 0002 732 C 0005 732 D... (7 Replies)
Discussion started by: cartrider
7 Replies

6. Shell Programming and Scripting

two file comparison

now i have a different file zoo.txt with content 123|zoo 234|natan 456|don and file rick.txt with contents 123|dog|pie|pep 123|tail|see|newt 456|som|sin|sim 234|pay|rat|cat i want to look for lines in file zoo.txt column1 that has same corresponding lines in column 1 of... (6 Replies)
Discussion started by: dealerso
6 Replies

7. Shell Programming and Scripting

File Comparison

Hi i have 2 csv files a.csv and b.csv with the same number of columns and a list of values in both of it. Each and every individual value in both the files need to compared and if it matches then print correct in a new csv file otherwise print Incorrect eg a.csv 1,12/27/2007,Reward,$10.00... (5 Replies)
Discussion started by: naveenn08
5 Replies

8. Shell Programming and Scripting

File Comparison- Need help

I have two text files which have records of thousand rows. Each row is having around 40 columns. Each column is tab delimited. Each row is delimited by newline character. My requirement is to find for each row i need to find whether any column is different between the two files. For each row i... (8 Replies)
Discussion started by: uihnybgte
8 Replies

9. Shell Programming and Scripting

file comparison

hi I have 2 files to comapre ,in file a sible column it is numbers,in file b2 numbers and other values with coma separated. i want compare numbers in file a with file b,and the out put put should be in C with numbers in both file a and b along with other columns of file b. i used folowing... (7 Replies)
Discussion started by: satish.res
7 Replies

10. Shell Programming and Scripting

File Comparison

I have to compare two text files, very few of the lines in these files will have some difference in some column. The files size is in GB. Sample lines are as below: 11111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd 11111122222222333333aaaaaaaaaabbbbbbbbbccccccccddeddd So assuming these... (19 Replies)
Discussion started by: net_shree
19 Replies
Login or Register to Ask a Question