Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Convert fixed value fields to comma separated values

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #8  
Old 4 Days Ago
mad man mad man is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 17 July 2018, 1:06 PM EDT
Posts: 54
Thanks: 27
Thanked 1 Time in 1 Post
Quote:
Originally Posted by RudiC View Post
This is as far as I can get:
Code:
awk '
        {getline X
         getline Y
         $0 = $0 FS X FS Y
         sub (/^--> TP *ID: /, _)
         FS = "|"
         gsub (/  +/, FS)

         $1 = $1
         for (i=1; i<=NF; i++)  sub (/^.*: */, _, $i)
         gsub (/,,/, ",")
         print
        }
' OFS=, file
TEST TP,ANSIXX99,D,TESTREFORMAT,X820XR99,820,ANSI,X,NONCTX,P
TEST TP,ANSIXX41,D,TESTREFORMAT,X820XR99,820,ANSI,X,004010,P
TEST TP,XXXXXXXX,D,TESTREFORMAT,XXXXXXXX,820,ANSI,X,004010,T

I can't isolate the DIR: I stuff. . . and, as said before, I wouldn't rely on this proposal .
Hi RudiC,

Thanks for bringing this awk command, but in my project we are not using awk any more because we are getting issues when we upgrade perl version.
Sponsored Links
    #9  
Old 4 Days Ago
wbport wbport is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 19 July 2018, 6:21 PM EDT
Location: Mississippi
Posts: 152
Thanks: 38
Thanked 22 Times in 22 Posts
Let's try this for a sed command file. You will need to specify -n before the name of your sed command file.
Code:
/-->/ {  N
         N
         s/  *//
         s/--//
         s/>//
         s/TP  ID: //
         s/ /~/
         s/  *XLATE KEY:  */ /
         s/\n/ /g
         s/  *AL:  */ /
         s/  *INT ID:  */ /
         s/  *XLATE TABLE:  */ /
         s/  *DOC ID:  */ /
         s/  *DIR:  */ /
         s/  *STD:  */ /
         s/  *COM:  */ /
         s/  *VERS:  */ /
         s/  *STAT:  */ /
         s/  */,/g
         s/~/ /
         s/^/ /
         p
       }

The Following User Says Thank You to wbport For This Useful Post:
mad man (4 Days Ago)
Sponsored Links
    #10  
Old 4 Days Ago
mad man mad man is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 17 July 2018, 1:06 PM EDT
Posts: 54
Thanks: 27
Thanked 1 Time in 1 Post
Quote:
Originally Posted by wbport View Post
Let's try this for a sed command file. You will need to specify -n before the name of your sed command file.
Code:
/-->/ {  N
         N
         s/  *//
         s/--//
         s/>//
         s/TP  ID: //
         s/ /~/
         s/  *XLATE KEY:  */ /
         s/\n/ /g
         s/  *AL:  */ /
         s/  *INT ID:  */ /
         s/  *XLATE TABLE:  */ /
         s/  *DOC ID:  */ /
         s/  *DIR:  */ /
         s/  *STD:  */ /
         s/  *COM:  */ /
         s/  *VERS:  */ /
         s/  *STAT:  */ /
         s/  */,/g
         s/~/ /
         s/^/ /
         p
       }

I will try this solution today and let you know the result.
Thanks.
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert column to quote and comma separated row wahi80 Shell Programming and Scripting 4 10-30-2014 02:44 PM
Needs help in parsing comma separated values avikaljain Shell Programming and Scripting 1 06-24-2013 02:41 PM
Convert comma separated file to fix length apenkov Shell Programming and Scripting 5 06-03-2013 08:47 AM
[solved] Comma separated values to space separated lost.identity UNIX for Dummies Questions & Answers 0 04-16-2013 05:59 AM
Remove whitespaces between comma separated fields from file nitinbjoshi UNIX for Dummies Questions & Answers 2 06-14-2008 08:14 AM



All times are GMT -4. The time now is 11:53 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?