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
RSS feeds to Email Mukka Shell Programming and Scripting 0 03-18-2008 06:27 PM
RSS Feeds of Threads craigp84 Post Here to Contact Site Administrators and Moderators 11 12-13-2007 08:33 AM
Spurious line feeds ajcannon Shell Programming and Scripting 2 10-29-2007 03:24 AM
Remove line feeds vsk Shell Programming and Scripting 8 06-16-2005 09:28 AM
carriage return/line feeds pitstop Shell Programming and Scripting 4 11-24-2003 11:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 8
Stumble this Post!
line feeds in csv

hi all,

i have csv file with three comma separated columns
i/p file
First_Name, Address, Last_Name
XXX, "456 New albany \n newyork, Unitedstates \n 45322-33", YYY\n
ZZZ, "654 rifle park \n toronto, canada \n 43L-w3b", RRR\n

is there any way i can remove \n (newline) from the second column
between the two double quotes"..."
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-31-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
will this do?
Code:
sed 's/\\n//g' csvFile
Reply With Quote
  #3 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 8
Stumble this Post!
i tried using sed commands !

thanks vgersh99
I tired that ! but it didn't work . all it does is removes all the \n from the csvfile.
( i.e ) all the data will be in one single line .
Reply With Quote
  #4 (permalink)  
Old 08-31-2005
Rakesh Ranjan's Avatar
Registered User
 

Join Date: Aug 2005
Location: India
Posts: 40
Stumble this Post!
Just change the pattern that vgersh99 said try something like
sed 's/\\n/\"^["]*\"'
\" for checking starting quotes ^["] for checking anything other than " (inside [] no metachr except '-' means anything so no need for \") and lastly \\n for newline. g as suggested by vgersh stands for globaly and so should not be used here.
I haven't run this (away from any Linux box) so in case of problem just fiddle with above pattern & if u still have problem plz. do tell me.

Last edited by Rakesh Ranjan; 09-01-2005 at 05:10 AM.
Reply With Quote
  #5 (permalink)  
Old 09-01-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
Quote:
Originally Posted by gowrish
thanks vgersh99
I tired that ! but it didn't work . all it does is removes all the \n from the csvfile.
that's right.
Quote:
Originally Posted by gowrish
( i.e ) all the data will be in one single line .
not really. given your sample file, the output would be: [on separate lines]
Code:
First_Name, Address, Last_Name
XXX, "456 New albany  newyork, Unitedstates  45322-33", YYY
ZZZ, "654 rifle park  toronto, canada  43L-w3b", RRR
Reply With Quote
  #6 (permalink)  
Old 09-01-2005
Registered User
 

Join Date: Aug 2005
Posts: 8
Stumble this Post!
ranjan

thanks man !


I tried ur suggestion, it didn't workout---i got this error msg!
sed: command garbled: s/\\n/\"^["]*\"
click on this link, there was a similar problem in this site , they had the solution too but not clear enough for me to solve my problem..
Remove Carriage returns between strings in a field
I didn't understand how they are calling the file, how the loop exactly workings
Please lookat the solution,please suggest me on this .
thanks
Gowrish
Reply With Quote
  #7 (permalink)  
Old 09-01-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
Quote:
Originally Posted by Rakesh Ranjan
Just change the pattern that vgersh99 said try something like
sed 's/\\n/\"^["]*\"'
\" for checking starting quotes ^["] for checking anything other than " (inside [] no metachr except '-' means anything so no need for \") and lastly \\n for newline. g as suggested by vgersh stands for globaly and so should not be used here.
I haven't run this (away from any Linux box) so in case of problem just fiddle with above pattern & if u still have problem plz. do tell me.
I think you're confusing the syntax of 's':
Code:
s/regular expression/replacement/flags
                   Substitute   the   replacement  string   for
                  instances  of  the  regular  expression in the
                  pattern  space.   Any  character  other   than
                  backslash  or newline can be used instead of a
                  slash to delimit the RE and  the  replacement.
                  Within the RE and the replacement, the RE del-
                  imiter itself can be used as a literal charac-
                  ter if it is preceded by a backslash.
                  An ampersand (&) appearing in the  replacement
                  will  be  replaced  by the string matching the
                  RE.  The special meaning of & in this  context
                  can   be   suppressed   by   preceding  it  by
                  backslash.  The characters \n, where  n  is  a
                  digit, will be replaced by the text matched by
                  the  corresponding  backreference  expression.
                  For each backslash (\) encountered in scanning
                  replacement from beginning to end, the follow-
                  ing  character  loses  its special meaning (if
                  any).  It is unspecified what special  meaning
                  is  given  to any character other than &, \ or
                  digits.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0