To remove decimal values from the field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To remove decimal values from the field
# 1  
Old 09-03-2012
Error To remove decimal values from the field

Hi Friends,

Hi Friends,

I have a file in the following format

file.txt

Code:
1|jHDJ|1345.0000000|384837843|39084938
2|jkaehjk|5784.00000|jhejhwej|3398934

i want to remove the 3rd field data decimal points from all lines

output.txt

Code:
1|jHDJ|1345|384837843|39084938
2|jkaehjk|5784 |jhejhwej|3398934

Plz help.

Last edited by Scrutinizer; 09-03-2012 at 02:04 PM.. Reason: code tags instead of quote tags
# 2  
Old 09-03-2012
Hi


Code:
$ awk '$3=int($3)' FS="|" OFS="|" file
1|jHDJ|1345|384837843|39084938
2|jkaehjk|5784|jhejhwej|3398934

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 09-03-2012
Quote:
Originally Posted by guruprasadpr
Hi


Code:
$ awk '$3=int($3)' FS="|" OFS="|" file
1|jHDJ|1345|384837843|39084938
2|jkaehjk|5784|jhejhwej|3398934

Guru.
Code:
awk '{$3=int($3)}1' FS="|" OFS="|" file

This is better because it will not skip lines if the 3rd field of any line has data such as 0.536.
This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 09-03-2012
Code:
sed 's:\.[^|]*::g' infile

This User Gave Thanks to complex.invoke For This Post:
# 5  
Old 09-03-2012
Code:
nawk -F\| -v OFS=\| '$3=substr($3,1,index($3,".")-1)' input.txt

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 09-03-2012
Hi all, Thanks for the help.. its working.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Decimal field round of

Hi, I want to round of decimal numbers in comma seperated lines till 2 decimal numbers. line will be like. ... (4 Replies)
Discussion started by: vishal0746
4 Replies

2. Shell Programming and Scripting

Rounding off decimal values

Hi Friends, This is my last post for today. My input file is chr1 100 200 chr1 123 300 chr1 300 400 chr1 420 520 chr10 132344343 132348674 When I try using this command awk '{v=($3+$2)/2; print $0"\t"v}' 1 This is my output chr1 100 200 150 chr1 123 300 211.5 (2 Replies)
Discussion started by: jacobs.smith
2 Replies

3. Shell Programming and Scripting

Working With Values After Decimal

I have two files which have to be compared. One of them has leading & trailing zeroes in certain fields. file1 ---- John,Rambo,20100101,2119.5,3302.39,100.07,22211.0 file2 ---- John,Rambo,20100101,000002119.50,0003302.39,00000.07,000022211.00 I am thinking of using diff to... (10 Replies)
Discussion started by: Sheel
10 Replies

4. Shell Programming and Scripting

CSV with commas in field values, remove duplicates, cut columns

Hi Description of input file I have: ------------------------- 1) CSV with double quotes for string fields. 2) Some string fields have Comma as part of field value. 3) Have Duplicate lines 4) Have 200 columns/fields 5) File size is more than 10GB Description of output file I need:... (4 Replies)
Discussion started by: krishnix
4 Replies

5. Shell Programming and Scripting

How to get decimal values ?

Hi All, In my script I've written like this- c=$( expr 100 / 3);echo $c The output coming is 33. but I want to see 33.33, decimal values too. How to get that? Thanks, Naresh (3 Replies)
Discussion started by: NARESH1302
3 Replies

6. Shell Programming and Scripting

How to sum up two decimal values?

I am running the following script : cat ind_sls_extr_UX.out_sorted | while read each_rec do count=`echo "${each_rec}" | cut -c1-2` if then final_amount=0 amount=`echo "${each_rec}" | cut -c280-287` echo "${amount}" final_amount=`expr ${amount} + ${amount}` ... (7 Replies)
Discussion started by: mady135
7 Replies

7. Shell Programming and Scripting

Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field. For example if N=3, we want the 3 best values for each entry: Entry1 ||| 100 Entry1 ||| 95 Entry1 ||| 30 Entry1 ||| 80 Entry1 ||| 50 Entry2 ||| 40 Entry2 ||| 20 Entry2 ||| 10 Entry2 ||| 50... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

8. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies
Login or Register to Ask a Question