The UNIX and Linux Forums  


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
Mac OS X 10.5.3 Update iBot UNIX and Linux RSS News 0 05-28-2008 08:00 PM
How to update passwd er_aparna Shell Programming and Scripting 5 03-02-2006 10:13 AM
NIM ML update govindarajan AIX 1 10-21-2005 06:40 AM
gcc update collins High Level Programming 0 10-28-2004 05:09 AM
update rsh UNIX for Dummies Questions & Answers 3 11-18-2002 07:35 PM

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

Join Date: Oct 2007
Posts: 8
update problem

Hello Friends, I am completely new to unix. Joined forum today. I have a problem which may seem very simple to you all. I will really appreciate your help.

I have a file.

Quote:
intel,80,Q-8029881900,ok
amd,82,Q-8055347900,ok
acer,40,Q-8033246100,ok
dell,22,Q-8098763500,ok
hp,33,Q-8011126700,ok
Purpose: to update this file as new product comes in. (product means: acer,intel, amd, etc..)

CASE 1: New Product: acer,41,Q-8033762700,ok
(you can consider this 4 fields seperated by comma as input arguments)
i.e. we have new product (acer41 instead 40) as below, then we need to add new line

output file should look like

Quote:
intel,80,Q-8029881900,ok
amd,82,Q-8055347900,ok
acer,40,Q-8033246100,ok
dell,22,Q-8098763500,ok
hp,33,Q-8011126700,ok
acer,41,Q-8033762700,ok
CASE 2: New Product: dell,22,Q-8098763501,ok
i.e. we have same product (dell 22 but Q change from Q-8098763500 to Q-8098763501) as below,then we need to replace that line

output file should look like

Quote:
intel,80,Q-8029881900,ok
amd,82,Q-8055347900,ok
acer,41,Q-8033762700,ok
dell,22,Q-8098763501,ok
hp,33,Q-8011126700,ok
Brief: This 2 case should keep working. lines will keep getting added when new product is there. & if same product & Q change then line will be replaced.

I will be really thankful if someone helps as soon as poss.
  #2 (permalink)  
Old 10-07-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
Without any validation or error handling:


Code:
echo "dell,22,Q-8098763501,ok" >> file
echo "acer,41,Q-8033762700,ok" >> file
awk -F, '{arr[$1$2] = $0} END { for (i in arr) { print arr[i] }}' file > newfile
mv newfile file

  #3 (permalink)  
Old 10-08-2007
onlyroshni onlyroshni is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 8
Thanks

Thank you very much admin. Perfect solution.
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 04:58 AM.


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