Sponsored Content
Top Forums Shell Programming and Scripting Sorting file by a field, and then by another field. Post 302373865 by steadyonabix on Sunday 22nd of November 2009 03:27:52 PM
Old 11-22-2009
With regard to the stable sort the simplest approach is to append a numeric key for the sort then remove it: -

Code:
[[ -a tmpfile ]] && rm tmpfile 

nawk -F":" ' { print $0"|"++_[$1] >> "tmpfile" } ' infileb 

sort -t"|" -k1n -k2n tmpfile | cut -d"|" -f1 > outfile 

cat outfile

Output: -

Code:
10:Mass Promo --      324
10:Mass Promo --      299
50:Mass Promo --     1077
50:Mass Promo --     1008
69:Mass Promo --      871
69:Mass Promo --      733
88:Mass Promo --        0
88:Mass Promo --        0
107:Mass Promo --       19
107:Mass Promo --       29

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting on last field

Hello I am trying to sort on the last field and it seems to have lost ideas on what to do. the file am sorting looks like this Tan\da\1223 hey\1234 two\three\think\4579 i want to sort on the last fields (1223, 1234 and 4579). thank you (2 Replies)
Discussion started by: ganiel24
2 Replies

2. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

3. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

4. UNIX for Dummies Questions & Answers

Sorting data in file based on field in another file

Hi, I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement. My two files as follows: File 1: 12345 1 2 2 2 0 0 12349 0 0 2 2 1 2 12350 1 2 1 2 2 2 . . . File2: 12350... (3 Replies)
Discussion started by: kasan0
3 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

7. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

8. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

9. Shell Programming and Scripting

Sorting file with CRLF within field, RS=$

OK below is what my sample file looks like. I need to sort by the Primary Key ie: {1:F01SAESVAV0AXXX0466020126} in the first record. Record seperator is $. I tried sort, but it completely messes it up. I am thinking I will need to use something like awk which understands the record seperator... (6 Replies)
Discussion started by: alfredo123
6 Replies

10. Shell Programming and Scripting

Need to replace last field in a file,if first field matches

Hi, Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username. Scenario: cat testfor1 deekshi:x:7082:7082::/home/deekshi:/bin/bash harini1:x:7083:7083::/home/harini1:/bin/bash Here,if first field contains "deekshi", then i should replace... (4 Replies)
Discussion started by: Sumanthsv
4 Replies
HTML::FormHandler::Result(3pm)				User Contributed Perl Documentation			    HTML::FormHandler::Result(3pm)

NAME
HTML::FormHandler::Result - form result object VERSION
version 0.40013 SYNOPSIS
This is the Result object that maps to the Form. my $result = $self->form->run( $params ); my $result2 = $self->form->run( $other_params ); my $value = $result->field('title')->value; my $fif = $result->fif; my $field_fid = $result->field('title')->fif; DESCRIPTION Although not experimental, the 'results' have not been exercised as much as the other parts of the code. If there is missing functionality or things that don't work, please ask or report bugs. The original FormHandler 'process' method, when used with persistent forms, leaves behind state data for a particular execution of 'process'. This is not optimal or clean from an architectural point of view. The intention with the 'result' object is to separate dynamic data from static. The 'form' object is treated as a kind of result factory, which will spit out results and leave the form in a consistent state. In the current state of implementation, the result object can be used to render a form: $result->render; However there are still open questions about how much of the form/field should be forwarded to the result. At this point, the number of forwarded methods is minimal. Mechanisms to make this more customizable are being considered. Dynamic select lists are not supported yet. Static select lists (that are the same for every form execution) should work fine, but lists that are different depending on some field value will not. Most of this object is implemented in HTML::FormHandler::Role::Result, because it is shared with HTML::FormHandler::Field::Result. AUTHOR
FormHandler Contributors - see HTML::FormHandler COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Gerda Shank. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-25 HTML::FormHandler::Result(3pm)
All times are GMT -4. The time now is 10:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy