The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting your data with msort iBot UNIX and Linux RSS News 0 05-19-2008 11:20 AM
sorting data using array in ksh ali560045 Shell Programming and Scripting 4 12-04-2007 04:26 AM
Sorting blocks of data alfredo123 Shell Programming and Scripting 8 07-05-2007 10:53 AM
Newbie Awk data sorting i_am_a_robot Shell Programming and Scripting 5 05-04-2007 07:33 AM
Recovering lost folders/files data Yorgy UNIX for Dummies Questions & Answers 0 03-15-2007 05:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-13-2008
Vinaykumar1 Vinaykumar1 is offline
Registered User
  
 

Join Date: May 2008
Posts: 16
Sorting data and place them in different folders

Hello Unix gurus,
I am new to Unix. I am working on some dummy project which involves unix scripting.

I have a query :

There is a file Number.dat which is of form say

AAA|123|4563|animal
AAA|1234|45634|animal2
BBB|123444|456312|bird
BBB|123445|456313|bird2

Here AAA,BBB are headers.
Now I want to sort Number.dat based on header and place them in different header.dat file.
How do I do that? I would be really greatful if some one helps me.


Thanks in advance
Vinay
  #2 (permalink)  
Old 05-13-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,215
What have you done to attempt to solve this problem yourself?
Post your sample script, and we'll see how we can assist.

Regards
  #3 (permalink)  
Old 05-13-2008
psiva_arul's Avatar
psiva_arul psiva_arul is offline
Registered User
  
 

Join Date: Jul 2007
Location: Bangalore, India
Posts: 95
using awk we can achive your solution.

using awk we can get the solution for your problem


if $1 ='AAA' we can redirect it into new file AAA.dat
and if $1 ='BBB' we can redirect it into new file BBB.dat


please use this way to get the solutions

Regards,
Siva.P
Bangalore
  #4 (permalink)  
Old 05-14-2008
Vinaykumar1 Vinaykumar1 is offline
Registered User
  
 

Join Date: May 2008
Posts: 16
Hello Franklin / Unix gurus,

My script is as follows:


#!/bin/ksh
sys=/export/home/vinay/Number.data
mod1=AAA
mod2=BBB

grep -h 'AAA' $sys > /export/home/vinay/AAA_$mod1.data
grep -h 'BBB' $sys > /export/home/vinay/BBB_$mod2.data


But I am not happy with the script since it has to traverse twice imto the Number.dat file


Also I some questions,

I want the process to use the Number.dat once rather than traversing twice.
Also, say if memory is full while script is running, then how should I handle it.
Kindly reply back if any one has a suggestion/script/solution

Thanks in advance.

Regards,
Vinay

Last edited by Vinaykumar1; 05-14-2008 at 01:18 AM..
  #5 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Both awk and sed have facilities for writing into multiple files as they read in a single pass down the file. psiva_arul is hinting in the same direction in the posting above.
  #6 (permalink)  
Old 05-14-2008
Vinaykumar1 Vinaykumar1 is offline
Registered User
  
 

Join Date: May 2008
Posts: 16
hello era /Unix gurus,
If you don't mind, can you assist in which fashion I can make use of sed into my script.

Thanks and Regards,
Vinay

Last edited by Vinaykumar1; 05-14-2008 at 01:43 AM..
  #7 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Googling is not an option?

Code:
sed -n '/^AAA/wAAA.dat
/^BBB/wBBB.dat' file
Notice that writing doesn't have any side effect (such as, for example, finish this line and fetch the next) so if you have patterns which overlap, you can get the same line written to multiple files (or need to write a slightly more complex script).
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions, solaris

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:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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