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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 12:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 12:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 07:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 04:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 12:39 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2005
Registered User
 

Join Date: Jan 2005
Posts: 97
sed or an awk script should help

num desc ind code

11 hi,feather y food
121 edible,oil y food
100 meal-pack y food
010 health,prod
120 lunch,pack


The above one is a flat file with the first line as column name.This is a comma delimited file with quote character as double quotes.

ie desc column has fields like "Hi,Feather" or may be "Hi,Fea"ther"

in short the record might look like

"10","Hi,Feather","y","Food"

this should go into the file but as in the example file above.Since delimiter is comma here ,I wud like to know if anyone can give me a script which can parse this the way i showed above and put into the file.ie Hi,Feather shud be in one column.Note: Its a vARIABLE LENGTH RECORD.
Reply With Quote
Forum Sponsor
  #2  
Old 08-17-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Because you have commas embedded inside the double-quoted text, this is not trivial.

Have a look a CVSparse and see if you can use it:

http://www.visi.com/~hawkeyd/csvutils.3.html
Reply With Quote
  #3  
Old 08-17-2005
inquirer's Avatar
Registered User
 

Join Date: Aug 2001
Posts: 78
is this what you want:

"10","Hi,Feather","y","Food"

into

10 Hi,Feather y Food

if that is the case you can simply do a sed...

sed -e 's/\",\"/ /g' -e 's/\'//g' filename

Reply With Quote
  #4  
Old 08-17-2005
RishiPahuja's Avatar
Registered User
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Wink

Quote:
Originally Posted by inquirer
is this what you want:

"10","Hi,Feather","y","Food"

into

10 Hi,Feather y Food

if that is the case you can simply do a sed...

sed -e 's/\",\"/ /g' -e 's/\'//g' filename

The first expression is clear to me it identifies < "," > expressions and substitutes with space. Let me know what are you trying to achieve with second expression -e 's/\'//g'
Reply With Quote
  #5  
Old 08-18-2005
inquirer's Avatar
Registered User
 

Join Date: Aug 2001
Posts: 78
typo error

should be:

sed -e 's/\",\"/ /g' -e 's/\"//g' filename

only human
Reply With Quote
  #6  
Old 08-18-2005
Registered User
 

Join Date: Jan 2005
Posts: 97
Will be bak

Thanks All, I was really busy figuring out similar pbm at my work place, will let you know my feedbak asap
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0