Need to modify a delimited file using UNIX commands. Please find description


 
Thread Tools Search this Thread
# 1  
Need to modify a delimited file using UNIX commands. Please find description

i have a '|' delimited file having 4 fields.
now i want to sort the data by combination of first three fields without changing order of 4th field.
input file looks like this:

Code:
3245|G|kop|45
1329|A|uty|76
9878|K|wer|12
3245|G|kop|15
1329|A|uty|56
9878|K|wer|2
3245|G|kop|105
1329|A|uty|506
9878|K|wer|20
3245|B|aop|15
1329|M|aty|56
9878|J|aer|2

now i want to have some modification of sorting that output file shoul look like:

Code:
3245|G|kop|45
3245|G|kop|15
3245|G|kop|105
1329|A|uty|76
1329|A|uty|56
1329|A|uty|506
9878|K|wer|12
9878|K|wer|2
9878|K|wer|20
3245|B|aop|15
1329|M|aty|56
9878|J|aer|2

Please Help. i am not getting desired output after many tries.

Last edited by Scrutinizer; 03-21-2013 at 06:41 AM.. Reason: code tags
# 2  
What's the logic of how your output is sorted? None of the output fields seem sorted.

BTW: Is this in the right forum? "Frequently asked questions"?
# 3  
Moved thread to other forum.
--

If you have GNU sort you could try the stable sort option (-s):

Code:
$ sort -s -t \| -k1,1n -k2,3 file
1329|A|uty|76
1329|A|uty|56
1329|A|uty|506
1329|M|aty|56
3245|B|aop|15
3245|G|kop|45
3245|G|kop|15
3245|G|kop|105
9878|J|aer|2
9878|K|wer|12
9878|K|wer|2
9878|K|wer|20

That would keep the relative order of the 4th column for records with the same first three columns unchanged like you asked.

But your output sample seems to only group the same records without changing the order in which the records appear for the first time. Is that what you are after?
# 4  
@Scrutinizer

-s flag , as suggested, does not support. it throws the error : not a recognized flag.

i am not sure whether sort is useful of not. but i want the output as i mentioned.

please suggest.
# 5  
Probably you would need to write a small script. What have you tried?
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #733
Difficulty: Medium
AmigaBASIC is a complied BASIC programming language implementation for the Amiga, designed and written by Microsoft.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and modify a huge file

Dear Forum, I have a rather large file with a few million lines looking like this: head -n 5 seq.txt >KF1.8.1 010011001011100010101110000000 >DF1.6.1 0101000010111010101011111100 >XC1.3.7 010110101011101010110000011 >GG5.1.1 0100011010111010101110001101 >HK1.2.2... (5 Replies)
Discussion started by: GDC
5 Replies

2. Shell Programming and Scripting

Modify comma delimited file columns.

Please help me to update a file which contains date values as below:- From:- "1912108",20161130,"2016-12-01-00.00.00.000000","2016-12-01-08.37.12.000000" "1912108",20161201,"2016-12-02-00.00.00.000000","2016-12-02-08.28.22.000000" To:- "1912108",2016-11-30,"2016-12-01... (7 Replies)
Discussion started by: KrishnaVM
7 Replies

3. Programming

Where to find sources of UNIX commands???

Dear friends, I believe that all unix commands are programs which are written in c language, please correct me if I am wrong. Now suppose that I want to see the c source of common commands like echo, ls, mkdir etc, where I can I find the source, linux is open source I believe, so the source for... (2 Replies)
Discussion started by: gabam
2 Replies

4. UNIX for Advanced & Expert Users

I need help to find some unix commands

Hey everyone, I need some help for some unix commands. - List all processes in the file "ProcessUser.txt" sorted by the users and in the file "ProcessName.txt" sorted by the name of the process. - How much time does the command "ls -alR /" need and compared to that, how much time is... (2 Replies)
Discussion started by: ZOCKER3000
2 Replies

5. UNIX for Dummies Questions & Answers

Please help me to find the functions for description

i have taken a screen shot of the question. http://www.magicscreenshot.com/MagicScreenshot/REAdbT956kE.png Please some one help me.:) (1 Reply)
Discussion started by: kjamsheed
1 Replies

6. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

7. Shell Programming and Scripting

find filenames like unix commands

Hi, I need to write a small script to search in some specific directories to check if any file is present with a unix command name... Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file. Please help Thanks, D (6 Replies)
Discussion started by: deepakgang
6 Replies

8. UNIX for Advanced & Expert Users

How to modify an existing pdf with unix shell commands

Hi, I know that to create a pdf file I can use the txt2pdf command. But if I would change an existing pdf file, by inserting lines in particular positions of this file, what can I use? And How? (3 Replies)
Discussion started by: fandwick
3 Replies

9. UNIX for Dummies Questions & Answers

Unix Find commands

thank you for the help (1 Reply)
Discussion started by: scooter17
1 Replies

10. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

Featured Tech Videos