Sponsored Content
Top Forums Shell Programming and Scripting sorting left-justified numeric values Post 302719283 by rovf on Monday 22nd of October 2012 10:42:02 AM
Old 10-22-2012
Question sorting left-justified numeric values

I have a file which looks roughly like this:

996 mmmmmmm
996 xxxxxxxxxxxxx
99600 ssssssssss
9964 fffffffffffff

and would like to sort it numerically on the first field. I tried:

sort -nr --key=1 ....

The output I get is:

99600 ssssssssss
9964 fffffffffffff
996 mmmmmmm
996 xxxxxxxxxxxxx

The output I would like to have:

996 mmmmmmm
996 xxxxxxxxxxxxx
9964 fffffffffffff
99600 ssssssssss

Of course I can solve this by writing a one-liner in, say, Perl or Ruby, but I wonder why my approach had not worked, and how I can use the genuine 'sort' command to achieve my goal.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting with multiple numeric keys

Data I want to sort :- 1 10 jj Y 2 100 vv B 19 5 jj A 1 11 hq D 3 8 op X 44 78 ds GG 1 8 hq D and want to sort based on the first 2 columns - which hold numeric values. Am using : cat filename | sort -nk 1,2 But the result is :- 1 10 jj Y 1 11 hq D (1 Reply)
Discussion started by: sinpeak
1 Replies

2. Shell Programming and Scripting

stripping out non-numeric values in a list

hi all, i'm very new to scripting and have the folllowing issue. I have used a few commands to get a list of numbers, but I need to strip away the non-numeric ones, and then need a total of all values. any ideas? root@unixserver # cat myfile | awk '{print $8}'| sort -rn 1504 1344 896 704... (2 Replies)
Discussion started by: badoshi
2 Replies

3. Shell Programming and Scripting

Remove non numeric values from a variable

Hello all, I am working on a basic script but need a little help. Issue: I am running a SQL Query using sqlplus and a shell script. I have the output of the statement stored as variable $A. $A is set to "other text here 45678754 other text here". I need to strip all text except that numeric... (13 Replies)
Discussion started by: ownedthawte
13 Replies

4. Programming

numeric values ending in 'U'

I am getting back on the C++ programming after many years away. I recently received an SDK that has code like this where numeric values end in 'U'. What does this mean? if ((ptr % 16U) == 0U) return buffer; (3 Replies)
Discussion started by: sneakyimp
3 Replies

5. Shell Programming and Scripting

How to check if the file contains only numeric values

How to check if the file contains only numeric values. I don't want to read entire file it eats lot of cpu Or any way which consumes less memory n cpu.. Please suggest -S (2 Replies)
Discussion started by: sunilmenhdiratt
2 Replies

6. Shell Programming and Scripting

Sorting the data right justified with through awk.

Dear all, I have a inputfile like some what like this - 1000.98651 1000.96696 999.98904 991.66864 986.51829 986.49467 17.44122 16.74039 16.74021 10.92725 desired output 1000.98651 1000.96696 0999.98904 (4 Replies)
Discussion started by: admax
4 Replies

7. Shell Programming and Scripting

sorting numeric array

Hi, I would like to do the following sorting, but the output is not what i expected. Why 222 and 2222 are not at the last two elements of array? awk 'BEGIN{a="22";a="2222";a="33";a="44";a="222";a="11";a="22";a="33";asort(a); for (i=1;i<=8;i++) print a}' 11 22 22 222 2222 33 33 44... (1 Reply)
Discussion started by: phoeberunner
1 Replies

8. Shell Programming and Scripting

Sorting the alpha numeric results of Hash

Hi All I've got a perl script that I'm having a problem with when it prints the output of a hash. Some background. I'm trying to merge two file with a similar structure but with different data. Here is a portion of the script I'm using. while (<INPUT>) { my... (0 Replies)
Discussion started by: kingpin2502
0 Replies

9. Shell Programming and Scripting

Sorting file based on a numeric column

Hi, I use UBUNTU 12.04. I have a file with this structure: Name 2 1245787 A G 12 14 12 14 .... Name 1 1245789 C T 13 12 12 12..... I would like to sort my file based on the second column so to have this output for example: Name 1 1245789 C T 13 12 12 12..... Name 2 1245787 A G 12 14... (4 Replies)
Discussion started by: Homa
4 Replies

10. UNIX for Beginners Questions & Answers

Replace a numeric values in a certain column

Hi All, I am trying to replace a certain value from one place in a file . In the below file at position 35 I will have 8 I need to modify all 8 in that position to 7 I tried awk '{gsub("8","7",$35)}1' infile > outfile ----> not working sed -i 's/8/7'g' infile --- it is replacing all... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies
ICONV_MIME_ENCODE(3)							 1						      ICONV_MIME_ENCODE(3)

iconv_mime_encode - Composes a MIMEheader field

SYNOPSIS
string iconv_mime_encode NULL (string $field_name, string $field_value, [array $preferences]) DESCRIPTION
Composes and returns a string that represents a valid MIME header field, which looks like the following: Subject: =?ISO-8859-1?Q?Pr=FCfung_f=FCr?= Entwerfen von einer MIME kopfzeile PARAMETERS
o $field_name - The field name. o $field_value - The field value. o $preferences - You can control the behaviour of iconv_mime_encode(3) by specifying an associative array that contains configuration items to the optional third parameter $preferences. The items supported by iconv_mime_encode(3) are listed below. Note that item names are treated case-sensitive. Configuration items supported by iconv_mime_encode(3) +-----------------+--------------------------+---+---+---+ | Item | | | | | | | | | | | | | Type | | | | | | | | | | | | Description | | | | | | | | | | | | Default value | | | | | | | | | | | | Example | | | | | | | | | | +-----------------+--------------------------+---+---+---+ | scheme | | | | | | | | | | | | | | | | | | | string | | | | | | | | | | | | Specifies the method to | | | | | | encode a field value by. | | | | | | The value of this item | | | | | | may be either "B" or | | | | | | "Q", where "B" stands | | | | | | for base64 encoding | | | | | | scheme and "Q" stands | | | | | | for quoted-printable | | | | | | encoding scheme. | | | | | | | | | | | | B | | | | | | | | | | | | B | | | | | | | | | | | input-charset | | | | | | | | | | | | | | | | | | | string | | | | | | | | | | | | Specifies the character | | | | | | set in which the first | | | | | | parameter $field_name | | | | | | and the second parameter | | | | | | $field_value are pre- | | | | | | sented. If not given, | | | | | | iconv_mime_encode(3) | | | | | | assumes those parameters | | | | | | are presented to it in | | | | | | the iconv.inter- | | | | | | nal_encoding ini set- | | | | | | ting. | | | | | | | | | | | | iconv.internal_encoding | | | | | | | | | | | | ISO-8859-1 | | | | | | | | | | | output-charset | | | | | | | | | | | | | | | | | | | string | | | | | | | | | | | | Specifies the character | | | | | | set to use to compose | | | | | | the MIME header. | | | | | | | | | | | | iconv.internal_encoding | | | | | | | | | | | | UTF-8 | | | | | | | | | | | line-length | | | | | | | | | | | | | | | | | | | integer | | | | | | | | | | | | Specifies the maximum | | | | | | length of the header | | | | | | lines. The resulting | | | | | | header is "folded" to a | | | | | | set of multiple lines in | | | | | | case the resulting | | | | | | header field would be | | | | | | longer than the value of | | | | | | this parameter, accord- | | | | | | ing to RFC2822 - Inter- | | | | | | net Message Format. If | | | | | | not given, the length | | | | | | will be limited to 76 | | | | | | characters. | | | | | | | | | | | | 76 | | | | | | | | | | | | 996 | | | | | | | | | | |line-break-chars | | | | | | | | | | | | | | | | | | | string | | | | | | | | | | | | Specifies the sequence | | | | | | of characters to append | | | | | | to each line as an end- | | | | | | of-line sign when "fold- | | | | | | ing" is performed on a | | | | | | long header field. If | | | | | | not given, this defaults | | | | | | to " " ( CR LF). Note | | | | | | that this parameter is | | | | | | always treated as an | | | | | | ASCII string regardless | | | | | | of the value of input- | | | | | | charset. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------------+--------------------------+---+---+---+ RETURN VALUES
Returns an encoded MIME field on success, or FALSE if an error occurs during the encoding. EXAMPLES
Example #1 iconv_mime_encode(3) example <?php $preferences = array( "input-charset" => "ISO-8859-1", "output-charset" => "UTF-8", "line-length" => 76, "line-break-chars" => " " ); $preferences["scheme"] = "Q"; // This yields "Subject: =?UTF-8?Q?Pr=C3=BCfung=20Pr=C3=BCfung?=" echo iconv_mime_encode("Subject", "Prufung Prufung", $preferences); $preferences["scheme"] = "B"; // This yields "Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=" echo iconv_mime_encode("Subject", "Prufung Prufung", $preferences); ?> SEE ALSO
imap_binary(3), mb_encode_mimeheader(3), imap_8bit(3), quoted_printable_encode(3). PHP Documentation Group ICONV_MIME_ENCODE(3)
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy