|
|
 | | From: | Adam Smith | | Subject: | Is this possible in the Bourne Shell w/ sed? | | Date: | Fri, 07 Jan 2005 21:59:18 -0800 |
|
|
 | Hello,
I am doing an automated preprocessing of data to be entered into a tab, \t, delimited text file prior to being loaded into a SQL DataBase. The fields of the raw data is "|" delimited and record terminated by a newline, \n.
Can I use sed to do a pattern substitution to replace the | with a tab? The constructs that I have come up with before have removed the "|" but failed to insert the metacharacter as a non-printing code. Suggestions (2) received have not worked either.
If this is a sed limitation, I'd welcome some info on it so that I can move on to another solution.
Thanks
|
|
 | | From: | Barry Margolin | | Subject: | Re: Is this possible in the Bourne Shell w/ sed? | | Date: | Sat, 08 Jan 2005 01:21:27 -0500 |
|
|
 | In article , Adam Smith wrote:
> Hello, > > I am doing an automated preprocessing of data to be entered into a tab, > \t, delimited text file prior to being loaded into a SQL DataBase. The > fields of the raw data is "|" delimited and record terminated by a > newline, \n. > > Can I use sed to do a pattern substitution to replace the | with a tab? > The constructs that I have come up with before have removed the "|" but > failed to insert the metacharacter as a non-printing code. Suggestions > (2) received have not worked either. > > If this is a sed limitation, I'd welcome some info on it so that I can > move on to another solution. > > Thanks
sed 's/|//g'
should do it. should be a literal TAB character, not the escape sequence. If you edit the file using Emacs, type C-q TAB; if you use vi, type C-v TAB.
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
|
|
 | | From: | Stephane CHAZELAS | | Subject: | Re: Is this possible in the Bourne Shell w/ sed? | | Date: | Sat, 8 Jan 2005 15:11:46 +0000 |
|
|
 | 2005-01-07, 21:59(-08), Adam Smith: > I am doing an automated preprocessing of data to be entered into a tab, > \t, delimited text file prior to being loaded into a SQL DataBase. The > fields of the raw data is "|" delimited and record terminated by a > newline, \n. > > Can I use sed to do a pattern substitution to replace the | with a tab? > The constructs that I have come up with before have removed the "|" but > failed to insert the metacharacter as a non-printing code. Suggestions > (2) received have not worked either. [...]
To transliterate characters, use tr:
tr '|' '\11' < infile > outfile
-- Stephane
|
|
 | | From: | Ross Presser | | Subject: | Re: Is this possible in the Bourne Shell w/ sed? | | Date: | 12 Jan 2005 03:32:09 GMT |
|
|
 | Stephane CHAZELAS wrote in news:slrnctvu1i.4at.stephane.chazelas@spam.is.invalid:
> 2005-01-07, 21:59(-08), Adam Smith: >> I am doing an automated preprocessing of data to be entered into a tab, >> \t, delimited text file prior to being loaded into a SQL DataBase. The >> fields of the raw data is "|" delimited and record terminated by a >> newline, \n. >> >> Can I use sed to do a pattern substitution to replace the | with a tab? >> The constructs that I have come up with before have removed the "|" but >> failed to insert the metacharacter as a non-printing code. Suggestions >> (2) received have not worked either. > [...] > > To transliterate characters, use tr: > > tr '|' '\11' < infile > outfile >
Never write it in 'C' if you can do it in 'awk'; Never do it in 'awk' if 'sed' can handle it; Never use 'sed' when 'tr' can do the job; Never invoke 'tr' when 'cat' is sufficient; Avoid using 'cat' whenever possible.
--Taylor's Laws of Programming
|
|
 | | From: | Shawn Corey | | Subject: | Re: Is this possible in the Bourne Shell w/ sed? | | Date: | Wed, 12 Jan 2005 08:20:33 -0500 |
|
|
 | Ross Presser wrote: > Never write it in 'C' if you can do it in 'awk'; > Never do it in 'awk' if 'sed' can handle it; > Never use 'sed' when 'tr' can do the job; > Never invoke 'tr' when 'cat' is sufficient; > Avoid using 'cat' whenever possible. > > --Taylor's Laws of Programming >
Just use Perl. -- Larry's Law
|
|
|