LinuxQuestions.org
Help answer threads with 0 replies.
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-08-2015, 08:17 AM   #1
kumar23kan
LQ Newbie
 
Registered: Oct 2015
Posts: 7

Rep: Reputation: Disabled
sort based on the nth character


I have file containg data like this

3u49
3u4c
3u4d
1iy8
3wye
1ipf
2ae2
2zat
1ipe
1geg
3gvc
2rhc

Based on the first 3 characters it has to be sorted and only unique line has to be printed based on the first 3 characters.

1geg
1ipe
1iy8
2ae2
2rhc
2zat
3gvc
3u49
3wye

I tried man for sort and uniq i couldn't figure out

thanks

Last edited by kumar23kan; 11-08-2015 at 08:20 AM.
 
Old 11-08-2015, 08:27 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
try sort -k and check KEYDEF (and look at the man page again)
 
1 members found this post helpful.
  


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] grep for pattern following the nth occurence of a character in a file cosminel Linux - Newbie 24 10-08-2013 03:34 AM
How to replace the space with newline character after every nth field in a line surajchalukya Linux - Newbie 13 03-08-2013 10:58 PM
[SOLVED] how to split a string of characters after nth character samanp Programming 2 08-15-2012 03:59 PM
how to delete nth character in a text file? xiawinter Linux - Software 3 05-13-2008 11:50 AM
Insert after every nth character using sed DoDo1975 Linux - Software 2 01-17-2007 07:59 PM


All times are GMT -5. The time now is 10:26 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