thousands separator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting thousands separator
# 8  
Old 04-12-2008
Hi.

The solution of radoulov worked for me, but the apostrophe copied and pasted in as an odd character -- it came in as a "?" in vi. I replaced it with a not-so-special single quote and, with the locale assignments and GNU Awk 3.1.4, it worked as shown above:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
GNU Awk 3.1.4

 Results from awk, locale C:
1234567

 Results from awk, locale en_US.UTF-8:
1,234,567

cheers, drl
# 9  
Old 04-12-2008
The apostrophe flag

Hi.

I didn't find the apostrophe flag description in man awk or Effective AWK Programing, 2nd, but in printf(3), we see:
Quote:
' For decimal conversion (i, d, u, f, F, g, G) the output is to be
grouped with thousands' grouping characters if the locale infor-
mation indicates any. Note that many versions of gcc cannot
parse this option and will issue a warning. SUSv2 does not
include %'F.
-- excerpt from man 3 printf
cheers, drl
# 10  
Old 04-12-2008
Yes, this works fine:
Code:
awk 'BEGIN{printf "%'"'"'d\n", 1234567890}'

# 11  
Old 04-13-2008
With sed:
Code:
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'

Regards
# 12  
Old 04-13-2008
Hi.

Who could live without a perl version:
Code:
perl -wpe '1 while s/(.*\d)(\d{3})/$1,$2/'

I like the brevity of the radoulov awk version, and the small size of the sed executable:
Code:
-rwxr-xr-x  1   41048 Nov 30  2004 /bin/sed*
-rwxr-xr-x  1  311308 Nov 26  2004 /usr/bin/awk*
-rwxr-xr-x  2 1057324 Mar  8  2005 /usr/bin/perl*

cheers, drl
This User Gave Thanks to drl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash-awk to process thousands of files

Hi to all, I have thousand of files in a folder with names with format "FILE-YYYY-MM-DD-HHMM" for what I want to send the following AWK command awk '/Code.*/' FILE-2014* I'd like to separate all files that have the same date to a folder named with the corresponding date. For example, if I... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

2. Shell Programming and Scripting

Search for patterns in thousands of files

Hi All, I want to search for a certain string in thousands of files and these files are distributed over different directories created daily. For that I created a small script in bash but while running it I am getting the below error: /ms.sh: xrealloc: subst.c:5173: cannot allocate... (17 Replies)
Discussion started by: danish0909
17 Replies

3. Shell Programming and Scripting

help to parallelize work on thousands of files

I need to find a smarter way to process about 60,000 files in a single directory. Every night a script runs on each file generating a output on another directory; this used to take 5 hours, but as the data grows it is taking 7 hours. The files are of different sizes, but there are 16 cores... (10 Replies)
Discussion started by: vhope07
10 Replies

4. UNIX for Dummies Questions & Answers

How to truncate thousands of file names

Folder of e-mails in maildir format had been corrupted. Typical file name is 1246281161.6777.m21JH:2,S . The " :2,S prevents " copying to another device. How can I simply remove the last four characters? (2 Replies)
Discussion started by: steve900
2 Replies

5. UNIX for Advanced & Expert Users

Copying Thousands of Tiny or Empty Files?

There is a procedure I do here at work where I have to synchronize file systems. The source file system always has three or four directories of hundreds of thousands of tiny (1k or smaller) or empty files. Whenever my rsync command reaches these directories, I'm waiting for hours for those files... (3 Replies)
Discussion started by: deckard
3 Replies

6. Solaris

script for Gzip thousands of file

Hi experts, I have thousands of file (data file and Gziped file) in same directory like below-- bash-2.05$ pwd /home/mmc bash-2.05$ file PP023149200709270546 TT023149200709270546: gzip compressed data - deflate method bash-2.05$ file PP027443200711242320 TT027443200711242320: ... (10 Replies)
Discussion started by: thepurple
10 Replies

7. Shell Programming and Scripting

Finding a specific pattern from thousands of files ????

Hi All, I want to find a specific pattern from approximately 400000 files on solaris platform. Its very heavy for me to grep that pattern to each file individually. Can anybody suggest me some way to search for specific pattern (alpha numeric) from these forty thousand files. Please note that... (6 Replies)
Discussion started by: aarora_98
6 Replies

8. UNIX for Advanced & Expert Users

Multiple (thousands) of Cron Instances

Hey all, I have a box running SUSE SLES 8 and in the past few months the box will randomly spawn thousands of instances of /USR/SBIN/CRON to the point where the box will lock up entirely. Upwards of 14000 instances! I imagine it's using up all of the available files that can be opened at one... (10 Replies)
Discussion started by: sysera
10 Replies
Login or Register to Ask a Question