Sponsored Content
Full Discussion: sed or awk to order a file
Top Forums Shell Programming and Scripting sed or awk to order a file Post 302324568 by radoulov on Thursday 11th of June 2009 05:30:53 AM
Old 06-11-2009
If Perl is acceptable:

Code:
perl -e'print sort{$b=~tr/,//<=>$a=~tr/,//}<>' infile

Otherwise:

Code:
awk -F, '{ print NF "\t" $0 }' infile | 
  sort -rn | 
    cut -f2-

GNU awk:

Code:
WHINY_USERS=oops awk -F, 'END {
  for (n in f) s[i++] = f[n]
  while (i--) print s[i]
  }  
{ f[NF] = NF in f ? f[NF] RS $0 : $0 }
' infile


Last edited by radoulov; 06-11-2009 at 06:50 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

using sed and regex to reverse order???

so i have been trying to learn how to manipulate text on my own and have gotten stumped... let's say i have a text file that says (highly simplified): people ordinary How would swap the order of the words.. I know i need to use sed and some kind of back reference but cannot make it... (2 Replies)
Discussion started by: urtherhoda
2 Replies

2. UNIX for Dummies Questions & Answers

Changing the order using sed

I have a text "abc def ghi" and I want to get it as "def abc ghi" I am using this echo "abc def ghi" | sed 's/\(*\)\(*\)/\2\1/' But I am not able to get the output, could anyone help me. Thanks (9 Replies)
Discussion started by: venu_nbk
9 Replies

3. Shell Programming and Scripting

AWK - printing certain fields when field order changes in data file

I'm hoping someone can help me on this. I have a data file that greatly simplified might look like this: sec;src;dst;proto 421;10.10.10.1;10.10.10.2;tcp 426;10.10.10.3;10.10.10.4;udp 442;10.10.10.5;10.10.10.6;tcp sec;src;fac;dst;proto 521;10.10.10.1;ab;10.10.10.2;tcp... (3 Replies)
Discussion started by: eric4
3 Replies

4. Shell Programming and Scripting

Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file. For example I have a file that says a b c d I want to change this to be d c b a Im trying to use sed to this by reading the file and then inserting each line at the top #!/usr/bin/ksh ... (3 Replies)
Discussion started by: MBGPS
3 Replies

5. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

6. Shell Programming and Scripting

sed string with any order

Hi, i have a strange prob. log file contains ip, protocol, user name, agent . these can be in any order. If log contains the above order able to fetch all details but if details are in diff order not able to fetch all details. using below command. grep -A50 "Entry " "/logs/file.log" \ |grep... (6 Replies)
Discussion started by: Satyak
6 Replies

7. Shell Programming and Scripting

sed - searching token in certain order

Hello. I would like to write a bash function which would return "true" if the search succeed else return anything else. something like if ] ; then exit 1 fi function my_funct () { find first occurrence $2 in $1 if not found return "false" from that position,... (6 Replies)
Discussion started by: jcdole
6 Replies

8. Shell Programming and Scripting

awk - Why does output order change?

I have this END section in an awk script: END { for (j in littlebin) { print (j, int(log(j)/log(2)) , littlebin) lbsum+=littlebin } for (i in bins) ... (6 Replies)
Discussion started by: treesloth
6 Replies

9. Shell Programming and Scripting

How order a data matrix using awk?

is it possible to order the following row clusters from ascending to descending. thanx in advance input 1 2 4 0 1 2 4 0 3 3 3 3 1 5 1 0 1 5 1 0 6 0 0 0 5 1 1 1... (4 Replies)
Discussion started by: quincyjones
4 Replies

10. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies
UNAFS(8)                                                      System Manager's Manual                                                     UNAFS(8)

NAME
unafs - script to warn users about their weak passwords SYNOPSIS
unafs password-files cell-name DESCRIPTION
This manual page documents briefly the unafs command, which is part of the john package. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. john, better known as John the Ripper, is a tool to find weak passwords of users in a server. The unafs tool gets password hashes out of the binary AFS database, and produces a file usable by John. SEE ALSO
john(8), mailer(8), unique(8), unshadow(8). The programs are documented fully by John's documentation, which should be available in /usr/share/doc/john or other location, depending on your system. AUTHOR
This manual page was written by Jordi Mallach <jordi@debian.org>, for the Debian GNU/Linux system (but may be used by others). John the Ripper and mailer were written by Solar Designer <solar@openwall.com>. The complete list of contributors can be found in the CRED- ITS file in the documentation directory. john June 03, 2004 UNAFS(8)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy