|
Home > Archive > Unix questions > December 2007 > help with sed command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
help with sed command
|
|
| Kristie 2007-12-17, 1:29 pm |
| Perhaps someone can help me with a sed command to do the following.
I have a file called Vouchsub.txt that looks like this
"00020" "1010994" "V7775101" "INV4379375-VCH0004993895" "FY 2008"
"Period 1-3" -136.04 0
"75600" "0003305" "V0196801" "INV240666-VCH0005023757" "FY 2008"
"Period 3-1" 72396 70812
I want to do a sed command on it in batch to find the "VCH" and append
the VCH and adjacent number right after it, enclosed in double quotes,
and separated by a space before and after so it looks like this.
"00020" "1010994" "V7775101" "INV4379375-VCH0004993895"
"VCH0004993895" "FY 2008" "Period 1-3" -136.04 0
"75600" "0003305" "V0196801" "INV240666-VCH0005023757" "VCH0005023757"
"FY 2008" "Period 3-1" 72396 70812
Any help would be greatly appreciated!!
Kristie
| |
| Barry Margolin 2007-12-18, 1:41 am |
| In article
<4bab1090-0aa7-4614-b945-3b8f6e5c5f1f@e67g2000hsc.googlegroups.com>,
Kristie <tkdunn11@gmail.com> wrote:
> Perhaps someone can help me with a sed command to do the following.
>
> I have a file called Vouchsub.txt that looks like this
>
> "00020" "1010994" "V7775101" "INV4379375-VCH0004993895" "FY 2008"
> "Period 1-3" -136.04 0
> "75600" "0003305" "V0196801" "INV240666-VCH0005023757" "FY 2008"
> "Period 3-1" 72396 70812
>
> I want to do a sed command on it in batch to find the "VCH" and append
> the VCH and adjacent number right after it, enclosed in double quotes,
> and separated by a space before and after so it looks like this.
>
> "00020" "1010994" "V7775101" "INV4379375-VCH0004993895"
> "VCH0004993895" "FY 2008" "Period 1-3" -136.04 0
> "75600" "0003305" "V0196801" "INV240666-VCH0005023757" "VCH0005023757"
> "FY 2008" "Period 3-1" 72396 70812
>
> Any help would be greatly appreciated!!
>
> Kristie
sed 's/\(VCH[0-9]*\)"/\& "\1"/' Vouchsub.txt > Vouchsub.txt.new
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Geoff Clare 2007-12-19, 1:23 pm |
| Barry Margolin wrote:
[vbcol=seagreen]
> sed 's/\(VCH[0-9]*\)"/\& "\1"/' Vouchsub.txt > Vouchsub.txt.new
Presumably you meant to type:
sed 's/\(VCH[0-9]*\)"/& "\1"/' Vouchsub.txt > Vouchsub.txt.new
(i.e. without escaping the &).
A slightly simpler alternative:
sed 's/VCH[0-9]*"/& "&/' Vouchsub.txt > Vouchsub.txt.new
--
Geoff Clare <netnews@gclare.org.uk>
|
|
|
|
|