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
existing file to a fixed length file cmanand Shell Programming and Scripting 3 01-25-2008 05:50 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM
search file, change existing value based on input (awk help) nortonloaf Shell Programming and Scripting 3 12-06-2006 01:35 AM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 04:38 AM
Creating a Mirror RAID With Existing Disk sysera Filesystems, Disks and Memory 2 02-09-2004 01:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-02-2007
skywayterrace skywayterrace is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
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
  #2 (permalink)  
Old 12-02-2007
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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 $?
Hope this helps.

bakunin
  #3 (permalink)  
Old 12-02-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Or with awk:

Code:
awk -F, '{printf("%s,%s,%s,%0.8d,%s,%s\n", $1,$3,$4,$5,$6,$7)}' infile > outfile
Regards
  #4 (permalink)  
Old 12-02-2007
skywayterrace skywayterrace is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
Thumbs up

I really Appreciate immediate Replyt.I am Going to Try both methods Today

thanks

Skyway
Sponsored Links
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 10: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