![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| existing file to a fixed length file | cmanand | Shell Programming and Scripting | 3 | 01-25-2008 01:50 PM |
| Extracting data from text file based on configuration set in config file | suparnbector | Shell Programming and Scripting | 3 | 08-09-2007 11:25 PM |
| search file, change existing value based on input (awk help) | nortonloaf | Shell Programming and Scripting | 3 | 12-05-2006 09:35 PM |
| i want to delete a file based on existing file in a directory | srivsn | Shell Programming and Scripting | 3 | 04-11-2006 01:38 AM |
| Creating a Mirror RAID With Existing Disk | sysera | Filesystems, Disks and Memory | 2 | 02-08-2004 09:40 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Creating a csv file based on Existing file
Hi I am Newbie to Unix.Appreciate Help from forum
user would loada b.Csv File(Below example) in /data/m/ directory.Program need to read the b.csc to extract certain column and create a new file /data/d/ directory as csv file with new name. User File Format 1232,samshouston,12345 houston,56666,20030811,78576,5,EA,789,SHELL 1456,dellshouston,2222 houston, 5644666,20030811,78576,5,EA,789,dell need to extract column1,column3,column4,column5,column7 and one more condition if the column4 length is lessthan 6 then add 000 before output wil look like in /data/o/tran.csv 1232,12345 houston,00056666,20030811,78576 1456,2222 houston,5644666,20030811,78576 Appreciate your help thanks Skyway |
| Forum Sponsor | ||
|
|
|
|||
|
Thats quite straightforward. Find a script skeleton below:
Code:
#! /bin/ksh
typeset fInput="/data/m/b.csc" # input filename
typeset fOutput="/data/o/tran.csv" # output filename
if [ -r "$fInput" ] ; then # perhaps there should be more input validation
print -u2 "unable to read input file"
exit 1
fi
sed 's/^\([^,]*,[^,]*,[^,]*,\)\([0-9]\{1,5\}\),/\1000\2/
s/^\([^,]*,\)[^,]*,\([^,]*,[^,]*,[^,]*,\)[^,]*,\([^,]*\).*$/\1\2\3/' $fInput > $fOutput
exit $?
bakunin |