shell script question
guys need some help with a simple shell script creation
I have a flat text file which has several thousand lines which I need to convert to a csv it's got a consistent format but basically want every time it hit's txt to create a new line with txt.1,line 1, line 2, line n txt.2,line 1, line 2, line n etc The input file looks like this txt.1 line 1 line 2 line n txt.2 line 1 line 2 line n txt.n line n Appreciate any help guys :) |
Originally Posted by P1_BEN
(Post 9295257)
guys need some help with a simple shell script creation
I have a flat text file which has several thousand lines which I need to convert to a csv it's got a consistent format but basically want every time it hit's txt to create a new line with txt.1,line 1, line 2, line n txt.2,line 1, line 2, line n etc The input file looks like this txt.1 line 1 line 2 line n txt.2 line 1 line 2 line n txt.n line n Appreciate any help guys :) You haven't given the shell environment and UNIX flavour you are using but here are a couple of things you can try, in the examples the file is called 'flatfile' sed -n 'H;${x;s/\n/,/g;s/^,//;s/,$//;p;}' flatfile or xargs < flatfile | tr ' ' ',' Have tried these on AIX 5.3 TL9 SP4 using the Korn Shell Environment. Should also in theory work in LINUX in BASH |
or you could load it into word, and record a macro to do it....
|
Originally Posted by warrenm2
(Post 9309741)
or you could load it into word, and record a macro to do it....
Had to do something similar a few years back when a company used to send us output from one database we didn't have to which we had to translate and input into another. The only way to do this was to use a scheduled shell script and then upload this using an integrated SQL script. It looks like he is doing something similar. :wonder: |
All times are GMT +1. The time now is 07:18 AM. |
© 2024 MH Sub I, LLC dba Internet Brands