Sponsored Content
Homework and Emergencies Homework & Coursework Questions Shell script/awk to sort text Post 302890070 by Lucas_0418 on Tuesday 25th of February 2014 04:05:43 AM
Old 02-25-2014
Hi guy,
Your awk version is important, don't know if your awk has a built in function 'asort'. If not, it will be hard for implement without 'sort'

Last edited by Lucas_0418; 02-25-2014 at 05:19 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sort with awk script

I have a file with four fields and an awk script that strips out one field displaying the remaining three. I have added headings for each of these fields such as Player - Year - RBIs then below it comes the data. What I am trying to do is sort the RBIs field in my script from most to least at the... (9 Replies)
Discussion started by: Trellot
9 Replies

2. Shell Programming and Scripting

Unable to use sort command in Shell Script

Hello All, I am creating a shell script that reads a file(test.txt) with the following data, 0.0.0.0 10.10.10.0 10.10.10.1 10.10.10.10 10.10.10.2 10.10.10.3 10.10.10.4 10.10.10.5 10.10.10.6 10.10.10.7 10.10.10.8 10.10.10.9 If I use the sort, the highest value I am getting is... (1 Reply)
Discussion started by: racbern
1 Replies

3. Shell Programming and Scripting

Text Proccessing with sort,uniq,awk

Hello, I have a log file with the following input: X , ID , Date, Time, Y 01,01368,2010-12-02,09:07:00,Pass 01,01368,2010-12-02,10:54:00,Pass 01,01368,2010-12-02,13:07:04,Pass 01,01368,2010-12-02,18:54:01,Pass 01,01368,2010-12-03,09:02:00,Pass 01,01368,2010-12-03,13:53:00,Pass... (12 Replies)
Discussion started by: rollyah
12 Replies

4. Shell Programming and Scripting

shell script to sort information in one file

Hi to all, anyway to create shell script to sort informations from one file and create new file with the sorted values? from file 30days.out -bash-3.00# more 30days.out user/str4@kl.com/INBOX user/tg1@johor.com/INBOX user/tg2@kedah.com/INBOX user/tg3@titangroup.com/INBOX... (3 Replies)
Discussion started by: Mr_47
3 Replies

5. Shell Programming and Scripting

AWK/Shell script for reading text file

Hello, I have a text file which has list of SQL Commands, from where I have grepped the lines where there is a specific string: grep <string> <file1> >> <file2> A sample of the file2 is: INSERT INTO PS_PWC_SP_ERN_DATA SELECT A.EMPLID ,B.COMPANY ,B.PAYGROUP , B.OTH_PAY FROM... (7 Replies)
Discussion started by: suddhasatwa_bha
7 Replies

6. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

7. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

8. Shell Programming and Scripting

Creating new users using a text file as imput (using only shell script and/or awk)

I need somebody who could help with an exercise. You have a text file called users.txt with this info inside: users.txt: user1:1234:/home/homedir1 ; user2:1234:/home/homedir2 ; user3:1234:/home/homedir3 ; user4:1234:/home/homedir4 ; The script should create an user using the... (2 Replies)
Discussion started by: marcosruiz
2 Replies

9. UNIX for Dummies Questions & Answers

How to sort a content of a text file using a shell script?

I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting. I've attached the 'Input file' and the 'expected output' to this thread. Details provided in the expected output file will provide details on how the sort needs to be done. ... (16 Replies)
Discussion started by: nkarthik_mnnit
16 Replies

10. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies
asort(1)						      General Commands Manual							  asort(1)

NAME
asort - Sorts or merges files and supports multiple collating weight sequences SYNOPSIS
asort [-m] [-o output_file] [-Abdfinruv] [-Ccollate_sequence] [-k keydef]... [-t character] [-T directory] [-y] [kilobytes] [-z record_size]... file... asort -c [-u] [-Abdfinruv] [-Ccollate_sequence] [-k keydef]... [-t character] [-T directory] [-y] [kilobytes] [-z record_size]... file... The following syntax is maintained for backward compatibility but may be withdrawn in a future release: asort [-Abcdfimnruv] [-Ccol- late_sequence] [-o output_file] [-t character] [-T directory] [-y] [kilobytes] [-z record_size] [+fskip] [.cskip] [-fskip] [.cskip] [-bdfinr]... file... OPTIONS
The asort command includes the same options as the sort command (see sort(1)) in addition to the following options: Specifies the collating weight sequence to be used in sorting the data files. When this option is specified, the asort command does not use the collating table from the locale database. Instead, the command uses a set of special system and user collating tables to determine the collating weights of characters, including user-defined characters (UDCs). The collate_sequence argument can be in long form (for example, "Pinyin Radical Stroke") or short form (for example, prs). The code- set of the locale determines which collation weight names can be specified for collate_sequence. The following list specifies the long and short collation weight names that are valid for supported codesets. For DEC Hanzi: Pinyon (or p) Radical (or r) Stroke (or s) For DEC Hanyu, Taiwanese EUC, and BIG-5: Phonetic (or p) Radical (or r) Stroke (or s) Uses a breadth-first sorting mechanism instead of the default depth-first mechanism to sort the input data. To have any effect, the -v option must be used together with the -C option. DESCRIPTION
The asort command sorts lines in its input files and writes the result to standard output. The asort command is similar to the sort com- mand. See the sort(1) reference page for information about features the two commands have in common. The asort command provides additional features for processing multiple collating weight sequences used with Asian languages, such as Chi- nese. For example, pinyon (p), stroke (s), and radical (r) are three dimensions along which characters can be ordered in Simplified Chi- nese. The -C option allows users to specify the priority level that these dimensions have during sorting. For example, -C srp specifies that characters should be sorted first by stroke, then by radical, then by pinyon. The specified sequence is applied to user-defined char- acters (UDCs) as well as to standard characters. When the -C option is specified, the default behavior of the asort command is to use a depth-first sorting mechanism to sort the input files. With the depth-first mechanism, pairs of multibyte characters in a sort field are compared by exhausting all the specified collat- ing weights and/or internal codes one at a time until the collating order is resolved. Only when two characters are identical is the next pair of characters compared. The depth-first sorting mechanism is also called character sorting. However, the asort command provides the -v option to use the Asian VMS-like breadth-first sorting mechanism. With the breadth-first mecha- nism, pairs of multibyte characters in a sort field are compared using the first collating weight for all the characters in the sort field first. Only when two sets of data in a sort field are computed to have the same collating order are succeeding collating weights used for resolving the collating order. The breadth-first sorting mechanism is sometimes called string sorting. NOTES
Currently, the asort command is supported for use only with Chinese codesets. EXIT STATUS
The asort command returns the following exit values: All input files were output successfully, or -c was specified and the input file was correctly sorted. If -c was specified, the file was not ordered as specified, or if the -c and -u options were both specified, two input lines were found with equal keys. An error occurred. EXAMPLES
Unless stated otherwise, the following examples assume the locale setting is zh_TW.dechanyu: To perform character sorting first by stroke and then by radical, enter: asort -C"Stroke Radical" names This command displays the lines in names sorted in ascending order according to the number of strokes in characters. If the number of strokes happen to be the same for two characters, the radicals of the characters determine how the characters are ordered.An alternative short form of the same command is as follows: asort -Csr names To perform string sorting first by stroke and then by radical in a way similar to the sort command available on an Asian VMS system, enter: asort -v -C"Stroke Radical" names SEE ALSO
Commands: sort(1) Functions: setlocale(3) Files: locale(4) Others: Chinese(5), i18n_intro(5) asort(1)
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy