Help need'd toread flat file at positions 23-30,67-89 per line using shell script
Hi,
I am a newbie to scripting.I need to read flat file say at positions 23-30,67-89....per line and write to another file with the fields comma separated in each line. Can someone please let me know how to go about it.Also it would be helpful if the steps can be explained. Thanks in advance, Sana |
Quote:
Quote:
Quote:
|
Quote:
There are many bash scripting tutorials out on the internet, and Google can help you find them. You're asking a vague question, with no samples of data, so it's hard to say step-by-step what you need to do, other than being very vague as well. |
Quote:
Code:
#!/usr/bin/perl The help page for substring on perldoc.perl.org should help you if you're confused about how to use substr. Oh yah, explaination: 1: #!/usr/bin/perl It's a perl script. 2: open(FILE1,"<./file.in") or die "Error: $!"; 3: open(FILE2,">./outfile.csv") or die "Error: $!"; Open one file for input (datafile), one for output (csv file). 4: while (<FILE1>) { 5: print FILE2 substr($_,22,8) . "," . substr($_,66,23) . "\n"; 6: } print the substr of the line starting from char 22 including next 8 chars add a comma do the same for char 66 including next 23 chars and add a newline. Repeat while there are lines in the input file 7: close(FILE1); 8: close(FILE2); 9: exit(); Close file 1 and 2, take your toys, go home. |
http://tldp.org Get the "Bash Guide for Beginners"
http://www.grymoire.com/Unix/ Really good tutorials and SED and AWK Ditto the comment that you should provide a sample of the file and the desired output. |
All times are GMT -5. The time now is 07:52 PM. |