The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Converting Space delimited file to Tab delimited file jeevs81 UNIX for Dummies Questions & Answers 16 02-26-2009 02:49 AM
Sort the fields in a comma delimited file swethapatil UNIX for Dummies Questions & Answers 3 10-24-2008 08:16 AM
combining fields in two text fields shocker Shell Programming and Scripting 3 01-16-2008 11:27 AM
formating output Krrishv Shell Programming and Scripting 20 02-02-2007 09:39 AM
Converting Tab delimited file to Comma delimited file in Unix charan81 Shell Programming and Scripting 22 01-20-2006 09:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
s_adu s_adu is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Delimited fields and formating

Hi

I am new to scripting. I have a file with following data

245|3|20090303456|3456
5072|34|20090304453|3546
245|28|20090304453|3547
5074|43|20090304453|3548

I want to format the file as below

245| 3|20090303456|3456
5072|34|20090304453|3546
245|28|20090304453|3547
5074|43|20090304453|3548

The main reason I want to do this is becase I want to sort the file using sort -n based on 1st 2 fields

If I do not reformat as above then sort -n will give

245|28|20090304453|3547
245|3|20090303456|3456
5072|34|20090304453|3546
5074|43|20090304453|3548

What I actually want is

245|3|20090303456|3456
245|28|20090304453|3547
5072|34|20090304453|3546
5074|43|20090304453|3548

Please help me.

Thanks and Regards
Adarsh
  #2 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
sort -n -t '|' -k1 -k2 myFile

  #3 (permalink)  
Old 04-23-2009
s_adu s_adu is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
Thx a lot. It works. I missed looking various options of sort
Thx again
Closed Thread

Bookmarks

Tags
awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0