|
|
|
|
|
|
| Author |
Message |
Jim Cornwall *nix forums beginner
Joined: 20 Jul 2005
Posts: 5
|
Posted: Thu Jul 20, 2006 2:48 pm Post subject:
Sed question (insert newline at specific points)
|
|
|
Hi all. I have a file which I would like to make more human-readable
since I have to use it for a database review. I would like to insert a
blank line in front of every line int he file that starts with a "Z".
Here's a severely trimmed-down sample of input, command, and results:
The input file (approx 26,000 lines, each "Z card" indicates a new
station's records, H / N / Y records are site info, followed by 1 to
many data records):
{jcorn} readdnelnc: % more peak
Z05010000 USGS
H05010000 4859501134050003030035SW1001000174.80 4500
N05010000 Belly River at International Boundary
Y05010000
305010000 19480617 1810 5.52
305010000 19490528 972 4.22
Z05010500 USGS
H05010500 4859201134550003030035SW1001000110.10 5100
N05010500 North Fork Belly River at International Bndry
Y05010500
305010500 19480616 386 4.23
305010500 19490528 146 3.22
Z05011500 USGS
H05011500 4857201135400003030035SW1001000161.00 4200
N05011500 Waterton River nr International Bndry
Y05011500
305011500 19480523 2510 6.30
305011500 19490528 1890 5.61
Command issued (borrowed from another ongoing thread on inserting
newlines at a "*"):
{jcorn} readdnelnc: % sed -e 's/^Z/\nZ/g' < peak > peak.edited
The results:
{jcorn} readdnelnc: % more peak.edited
nZ05010000 USGS
H05010000 4859501134050003030035SW1001000174.80 4500
N05010000 Belly River at International Boundary
Y05010000
305010000 19480617 1810 5.52
305010000 19490528 972 4.22
nZ05010500 USGS
H05010500 4859201134550003030035SW1001000110.10 5100
N05010500 North Fork Belly River at International Bndry
Y05010500
305010500 19480616 386 4.23
305010500 19490528 146 3.22
nZ05011500 USGS
H05011500 4857201135400003030035SW1001000161.00 4200
N05011500 Waterton River nr International Bndry
Y05011500
305011500 19480523 2510 6.30
305011500 19490528 1890 5.61
As you can see, I got an 'n' inserted before the 'Z', not a newline.
What did I do wrong in the sed command?
Thanks in advance,
Jim Cornwall
(USGS Water Resources, speaking for myself not the US Gov) |
|
| Back to top |
|
 |
jue *nix forums beginner
Joined: 05 Jul 2006
Posts: 4
|
Posted: Thu Jul 20, 2006 3:17 pm Post subject:
Re: Sed question (insert newline at specific points)
|
|
|
Jim Cornwall schrieb:
| Quote: | Hi all. I have a file which I would like to make more human-readable
since I have to use it for a database review. I would like to insert a
blank line in front of every line int he file that starts with a "Z".
Here's a severely trimmed-down sample of input, command, and results:
The input file (approx 26,000 lines, each "Z card" indicates a new
station's records, H / N / Y records are site info, followed by 1 to
many data records):
....
{jcorn} readdnelnc: % sed -e 's/^Z/\nZ/g' < peak > peak.edited
....
As you can see, I got an 'n' inserted before the 'Z', not a newline.
What did I do wrong in the sed command?
|
no solution for sed, but:
perl -pe 's/^Z/\nZ/g;' < peak > peak.edited
Thomas
ps.
I am sure there is a solution for your sed-snipped, but:
perl will give you much more power to extract the interesting data...
but that's not for comp.unix.shell |
|
| Back to top |
|
 |
Radoulov, Dimitre *nix forums beginner
Joined: 14 Dec 2005
Posts: 26
|
Posted: Thu Jul 20, 2006 3:27 pm Post subject:
Re: Sed question (insert newline at specific points)
|
|
|
| Quote: | Hi all. I have a file which I would like to make more human-readable
since I have to use it for a database review. I would like to insert a
blank line in front of every line int he file that starts with a "Z".
[...] |
$ sed 's/Z/\
Dimitre |
|
| Back to top |
|
 |
Jim Cornwall *nix forums beginner
Joined: 20 Jul 2005
Posts: 5
|
Posted: Thu Jul 20, 2006 4:09 pm Post subject:
Re: Sed question (insert newline at specific points)
|
|
|
Thomas J. wrote:
| Quote: | Jim Cornwall schrieb:
Hi all. I have a file which I would like to make more human-readable
since I have to use it for a database review. I would like to insert a
blank line in front of every line int he file that starts with a "Z".
Here's a severely trimmed-down sample of input, command, and results:
The input file (approx 26,000 lines, each "Z card" indicates a new
station's records, H / N / Y records are site info, followed by 1 to
many data records):
...
{jcorn} readdnelnc: % sed -e 's/^Z/\nZ/g' < peak > peak.edited
...
As you can see, I got an 'n' inserted before the 'Z', not a newline.
What did I do wrong in the sed command?
no solution for sed, but:
perl -pe 's/^Z/\nZ/g;' < peak > peak.edited
Thomas
ps.
I am sure there is a solution for your sed-snipped, but:
perl will give you much more power to extract the interesting data...
but that's not for comp.unix.shell
|
Thanks, that did the trick. No need to extract anything else, I was
just looking to separate site records. I now have what I needed...
Jim |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Mon Dec 01, 2008 10:03 pm | All times are GMT
|
|
Mobile Phone | Online Advertising | Loans | Advertising | Project cars for sale
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|