cut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut
# 1  
Old 08-17-2007
cut

Hi,

I need to manipualte the data in the file below so that the value fields on each line are truncated to just two decimal places. Meaning i want to delet everything after two decimal places on each record in the file.

I have highlighted the first value field.

02331814579359.6500000004
0348991976138.6767000001
04201280145145.4400000002
08654312609500.3800000002
09155934830963.3300000018
10166784506.0399999991
11884517456.5800000032
12108694361.4000000014
1324377035481.8500000004
15962912770.06
170101083.84826

I can obviously use SED to find the decimal point, but can someone please advise on how to use cut in order to truncate the values after the decimal point as required ?

Thanks
Rgds

Paul
# 2  
Old 08-17-2007
One method..assuming the file contents are of the given format.

Code:
sed 's/\(.*\)\.\([0-9][0-9]\)\(.*\)/\1.\2/' file

# 3  
Old 08-17-2007
Code:
awk -F"|" '{ printf "%0.2f\n", $2 }' filename

change the delimiter as per requirement
# 4  
Old 08-17-2007
Hi,

Thanks this works fine.

Rgds

Paul
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies
Login or Register to Ask a Question