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 > 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
Help needed in removing intermediate segments from a pipe delimited segment file naren_0101bits Shell Programming and Scripting 3 12-03-2007 11:54 AM
To split a string to obtain the words delimited by whitespaces Sudhakar333 Shell Programming and Scripting 4 08-06-2007 03:26 PM
splitting a pipe delimited file in unix ddedic Shell Programming and Scripting 4 03-20-2007 01:16 AM
Grep for NULL in a pipe delimited file sureshg_sampat Shell Programming and Scripting 5 11-21-2006 06:15 AM
Fast way to split a tab delimited file madhunk Shell Programming and Scripting 13 05-18-2006 04:36 PM

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 05-31-2008
njgirl njgirl is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
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|*|
  #2 (permalink)  
Old 05-31-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,764
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
  #3 (permalink)  
Old 05-31-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,312
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
  #4 (permalink)  
Old 06-01-2008
njgirl njgirl is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
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
  #5 (permalink)  
Old 06-18-2008
freelong freelong is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 38
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}
Closed Thread

Bookmarks

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 05:06 PM.


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