trim and compare


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trim and compare
# 1  
Old 07-17-2009
trim and compare

1) I want to trim the zeros of the 1st file so they match the second file
2) run an automatic diff and error in lines that dont match

File1
Code:
0.8035500
1.4138000
1.6381500
1.9256110
3.8075000
13.3270000
13.4155000
94.2700000
937.7000000

File2
Code:
0.80355
1.4138
1.63815
3.8075
1.925611
13.327
13.4155
94.27
937.7


Last edited by vgersh99; 07-17-2009 at 08:59 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-17-2009
Just a head start
Code:
sed 's/0*$//' file

# 3  
Old 07-17-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 07-20-2009
thanks that was it...
# 5  
Old 07-23-2009
unfortuately the sed one line turns data into whole numbers too..

e.g

file 1

had 937.0

with sed one liner"

file 2 becomes

937.

hence the diff flags it


anyone know how to enhance the sed one liner to take this into acct?

maybe have exception if there is a decimal before and not to delete that..

please let me know

thanx
# 6  
Old 07-23-2009
Code:
sed 's/0*$//;s/\.$//' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trim Space

In Shell, I have output of a unix command as test1 test2015 but I want it as test1 test2015 can anyone help me out. Use code tags, thanks. (3 Replies)
Discussion started by: OscarS
3 Replies

2. Shell Programming and Scripting

How to trim the zero's after decimal?

Hello all, I have an XML with below content from which i need to remove the trailing zeros, like 123.00 should be converted to 123 and 123.01200 to 123.012 Below is the sample excerpt data from XML file. My input file size could be approximately 5 GB or less. CURRENT:... (10 Replies)
Discussion started by: Ariean
10 Replies

3. Shell Programming and Scripting

Trim the data

i am passing below inputfils using while loop and ouput should be trim as below INPUT: src_SPS_d_Comment_Tran_File_20130417_001.dat src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat src_SPS_d_Letter_Tran_File_20130417_001.dat src_SPS_d_Loan_Level_File_20130417_001.dat... (8 Replies)
Discussion started by: katakamvivek
8 Replies

4. Shell Programming and Scripting

Trim spaces

All, i am comparing the output of one command to a numberic if ] but my problem is the output of follwoing is but but has some leading columns. I don't have any problme in LINUX and HP-UX. But only in AIX i am getting the leading spaces. I have developed my script on LINUX but when... (4 Replies)
Discussion started by: rcc50886
4 Replies

5. Shell Programming and Scripting

Help with awk trim

I am trying to trim spaces for the fixed width file starting from location 129 and of length 20. I am expecting only around 40 records that will have length greater than 9. But i am getting around 4000 records. Please help me correct the following. nawk '{if (a=length(gsub(/... (2 Replies)
Discussion started by: pinnacle
2 Replies

6. Shell Programming and Scripting

Trim Filename

Hi All, I have a file named as FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_20110622-161429_07_WFR12345_20110622-161429_20110712-125228.data.dis I want to generate a directory taking only the 7XYZ12345.000_WFR12345 The length and format of the Filename will be the same... (2 Replies)
Discussion started by: asheshrocky
2 Replies

7. Shell Programming and Scripting

Trim a new line

Okay, I am trying to make a bash script to get a certain domains IP address (my home ip). My home is on a DHCP lease from my ISP, so I cannot always trust the IP address to remain constant. This is what I have so far for it: alias ip-home="ping -c 1 example.com | grep 'PING' | cut -d'(' -f2 |... (5 Replies)
Discussion started by: tnanek
5 Replies

8. Shell Programming and Scripting

trim letters

Hello, I have a list of words.. ranging from 4 to any characters long.. to not more than 20 though. How can I select only first seven letters of the list of words? example:- wwwwwwwwww eeeee wererreetf sdsarddrereewtewt sdsdsds sdsd ereetetttt ewtwertwrttrttrtrtwtrww I... (10 Replies)
Discussion started by: fed.linuxgossip
10 Replies

9. Shell Programming and Scripting

Trim

Hello, I am passing a filename to a script to draw parameters from it. However, I want to use part of the filename as a parameter. The filename is transfer_ccf_3731_10.sh but I only need the 3731_10 part of it. Is this possible? Any help or suggestions would be appreciated! Regards, J. (4 Replies)
Discussion started by: JWilliams
4 Replies

10. Shell Programming and Scripting

trim whitespace?

I'm trying to find a command that will trim the white space off a string. e.g. $str = " stuf " $str = trim ( $str ) echo $str // ouput would just be stuf Thanks, Mark (4 Replies)
Discussion started by: msteudel
4 Replies
Login or Register to Ask a Question