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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help needed in removing intermediate segments from a pipe delimited segment file naren_0101bits Shell Programming and Scripting 3 12-03-2007 07:54 AM
To split a string to obtain the words delimited by whitespaces Sudhakar333 Shell Programming and Scripting 4 08-06-2007 11:26 AM
splitting a pipe delimited file in unix ddedic Shell Programming and Scripting 4 03-19-2007 09:16 PM
Grep for NULL in a pipe delimited file sureshg_sampat Shell Programming and Scripting 5 11-21-2006 02:15 AM
Fast way to split a tab delimited file madhunk Shell Programming and Scripting 13 05-18-2006 12:36 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Stumble this Post!
How to split pipe delimited file

I have a pipe delimited input file as below. First byte of the each line indicate the record type. Then i need to split the file based on record_type = null,0,1,2,6 and create 5 files. How do i do this in a ksh script? Pls help

|sl||SL|SL|SL|1996/04/03|1988/09/15|C|A|sl||||*|
0|sl||AX||||SL|1973/04/01|1973/04/01|A|A|sl|||*|
1|sl|RCBH|OR||desc||sl||2008/04/16||A|novel||||RCBH||||||desc|||||*|
2|sl|SL|IA|02||desc||MPL||2008/04/16|A|A|novel|632||BUILDING|1 |N|MAIN|ST||1 N MAIN ST|||*|
6|sl|SL|FL|JD|U31||||||A|B|X|desc||clon8008||BT||2007/12/20|A|A|*|
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-31-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,841
Stumble this Post!
Code:
awk '{  /^\// print $0 > "fileNULL";next
          /^0/ print $0 > "file0"; next
          /^1/  print $0 > "file1"; next
          /^2/ print $0 > "file2"; next
          /^6/ print $0 > "file6"; next
        }' hugefile
Reply With Quote
  #3 (permalink)  
Old 05-31-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
Another one, it creates the files with the names "file_null", "file_0", "file_1" etc.

Code:
awk -F"|" '{print $0 > ($1==""?"file_null":"file_"$1)}' file
Regards
Reply With Quote
  #4 (permalink)  
Old 05-31-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Stumble this Post!
Thanks Jim... i have used as you suggested,but getting below errors. I am very new to scripting... pls help

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 2
awk: illegal statement near line 2
awk: syntax error near line 3
awk: illegal statement near line 3
awk: syntax error near line 4
awk: illegal statement near line 4
awk: syntax error near line 5
awk: illegal statement near line
Reply With Quote
  #5 (permalink)  
Old 06-18-2008
Registered User
 

Join Date: Apr 2008
Posts: 24
Stumble this Post!
Code:
/^\|/ {print $0 > "filenull"; next}
/^0/ {print $0 > "file0"; next}
/^1/ {print $0 > "file1"; next}
/^2/ {print $0 > "file2"; next}
/^6/ {print $0 > "file6"; next}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0