Basic file processing question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Basic file processing question
# 1  
Old 12-02-2009
Basic file processing question

I have a csv file with 3 columns. Column 1 is a date "mm/dd/yyyy", column 2 is a dollar amount (e.g. "100.00") & column 3 in a description of where the transaction took place (e.g. "CHECK CRD PURCHASE 10/07 ACME INC USA")

so...
"10/01/2009","100.00", "CHECK CRD PURCHASE 10/07 ACME INC USA"

I would like to output a file like such:
20091001,100.00,CHECK CRD PURCHASE 10/07 ACME INC USA,ACME INC

Where ACME INC is derived from a "lookup" file, something like (s/.*ACME INC.*/ACME INC/).

So my questions:
1)What's the best method for maintaining the lookup file, how can I handle a vendor who appears in the input file and not in the lookup file? i.e. flag them as "undefined"
2)How do I append the 4th column with the lookup result
3)how do modify the date
4)how do I persist the FS"," such that the output is still .csv

Thanks in advance!
# 2  
Old 12-02-2009
Try this:

Code:
awk -F, -v var="AMCE INC" '
{split($1,a,"/");$1=a[3] a[2] a[1]}
$0 ~ var {$(NF=1)=var}1
' OFS="," file

If you have "ACME INC" in a variable eg myvar then the first part should be -v var=$myvar
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Basic question regarding root file system copy to another disk

Hello, I am creating a new disk using the following command: dd if=/dev/zero of=/export/home/ramdisk/0 bs=512 count=4096k after creating the disk, i tool a ufsdump of a solaris 10 filesytem (disk size 512MB) ufsdump -cvf /export/home/ufsdump/sol_orig /and then restored the dump files onto... (10 Replies)
Discussion started by: Zam_1234
10 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

Basic line reading and file merge question

No doubt these questions have been answered many times, but I struggled to find them - sorry. 2 questions: 1. I wish to read in a file one line at a time and do 'stuff' with it, such as: file="tst2" while IFS= read -r line do echo `wget -qO -... (3 Replies)
Discussion started by: Golpette
3 Replies

4. Shell Programming and Scripting

Question about File Processing

I have a file with the format CKF,23G ckf,234M CKF,2356K DFK,4589M DFK,343K dfk,3434M DFK,34G DFK,34343M, DFK,3476G FGK,34k KLK,43G KLK,3G I would like to group by the 3-letter code in the beginning of the file and sum up the second column in giga bytes and output a file like... (3 Replies)
Discussion started by: inditopgun
3 Replies

5. Shell Programming and Scripting

Monitoring a file - Basic Bash Question

*This is not homework I am new to UNIX and want to try this Monitoring a file demo* *If this is the wrong forum please move it - im new to the forums* $1 = the file to be monitored $2 = the time for the file to sleep If the file gets changed (using -nt) it will send my username mail saying... (2 Replies)
Discussion started by: Nolan-
2 Replies

6. Solaris

basic question on sd.conf and lpc.conf file

Hello Guys, Do we need to configure this file only if we add SAN disk or even if we add local disk, do we need to modify? (4 Replies)
Discussion started by: mokkan
4 Replies

7. Shell Programming and Scripting

basic nc question

i'm doing this in one terminal: nc -lu 7402 and it appears to start listening properly, then in another i do this: echo "hello" | nc -u localhost 7402 and nothing happens on the listening terminal - what am i doing wrong? thanks. (7 Replies)
Discussion started by: peterworth
7 Replies

8. Shell Programming and Scripting

basic question

hi, I have a basic question,, i am in a directory called /intas/OCU_3.9.1/sbin ocuut1@france>mv itsa_tcs itsa_tcs_old mv: itsa_tcs_old: rename: Permission denied i am logging as the owner of the file. when i am doing this i am getting the above error of permission denied. I know... (3 Replies)
Discussion started by: namishtiwari
3 Replies

9. UNIX for Dummies Questions & Answers

Really basic question....

Hello all. Let me start off by saying I know a little more then it seems by me asking this question... here goes I have an old 486 box and I want to start messing around with unix. I've been taking classes for 3 or 4 years in c programming in unix, so I am used to the commands and such, but I... (1 Reply)
Discussion started by: robherms
1 Replies

10. UNIX for Dummies Questions & Answers

basic question

I have some basic doubts. Can someone clarify in this forum? 1)if then eval ' tset -s -Q -m ':?hp' ' else eval ' tset -s -Q ' what does it exactly mean in .profile? 2) what are 'nobody' and 'noaccess' usernames in /etc/passwd file. ... (3 Replies)
Discussion started by: asutoshch
3 Replies
Login or Register to Ask a Question