LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-07-2012, 08:30 PM   #1
jachaja
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Rep: Reputation: Disabled
awk and sort for a chain of characters in a file


Hi all,

I have a file with a lot of records similar to this:

023456AB2543999210709
022656AB2543999210409
024556AB2543999200709
024556AB2543999200909

I want to sort this file by using two parts of each record, for example: positions 3 to 4 like one field ascending and
positions 16 to 19 like other field descending.

The result:
022656AB2543999210409
023456AB2543999210709
024556AB2543999200909
024556AB2543999200709

how can i do it? It is possible using awk?

Thanks.
 
Old 11-08-2012, 01:31 AM   #2
replica9000
Member
 
Registered: Jul 2006
Location: USA
Distribution: Debian, FreeBSD, Android
Posts: 998
Blog Entries: 2

Rep: Reputation: 212Reputation: 212Reputation: 212
Does it have to be awk? Why not sort?
Code:
cat yourfile | sort -k1.3,1.4n -k1.16,1.19r
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk - sort characters within each line danielbmartin Programming 7 11-07-2012 09:52 PM
delimiter file need to insert characters, awk problem. fantasy1215 Programming 5 07-09-2012 05:44 AM
using SED or AWK to cut data from a file, between certain characters hugh86 Linux - Newbie 18 10-28-2010 05:17 AM
Problems using awk/sed/sort with a ucs-2le encoded file Jem7v! Programming 3 02-05-2010 07:03 AM
how to delete duplicates entries in xml file using sed/awk/sort ? catzilla Linux - Software 1 10-28-2005 03:57 PM


All times are GMT -5. The time now is 02:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration