LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07: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 07:20 AM.
 
Old 11-08-2015, 07:27 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:17 AM.

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
Open Source Consulting | Domain Registration