I have a file that looks like this:
$ head newsrc-news.eternal-september.org-test
nl.newsgroups.announce: 1-1329
free.uk.amateur-radio: 1-15497
uk.media.radio.misc: 1-456
uk.radio.amateur: 1-377688,377690,377692,377694-377697,377699,377701-377704 uk.radio.amateur.moderated: 1-6432
uk.legal.moderated: 1-378428
comp.security.ssh: 1-3221
alt.comp.software.newsreaders: 1-481
uk.net.news.moderation: 1-64428
free.uk.legal: 1-275
I want to convert all the last part of the lines from 1-whatever to 1-1
I have tried:
$ sed -i 's/"1-*"/'1-1'/g' newsrc-news.eternal-september.org-test
and
$ sed -i 's/"1-*"/"1-1"/g' newsrc-news.eternal-september.org-test
$ sed -i 's/"1-*"/1-1/g' newsrc-news.eternal-september.org-test
but none of them does the job.
If I do:
$ sed -i 's/1-*/"1-1"/g' newsrc-news.eternal-september.org-test
then:
$ head newsrc-news.eternal-september.org-test
nl.newsgroups.announce: "1-1""1-1""1-1""1-1"329
free.uk.amateur-radio: "1-1""1-1""1-1""1-1"5497
uk.media.radio.misc: "1-1""1-1"456
uk.radio.amateur: "1-1""1-1"377688,377690,377692,377694-377697,377699,37770"1-1""1-1"377704 uk.radio.amateur.moderated: "1-1""1-1"6432
uk.legal.moderated: "1-1""1-1"378428
comp.security.ssh: "1-1""1-1"322"1-1""1-1"
alt.comp.software.newsreaders: "1-1""1-1"48"1-1""1-1"
uk.net.news.moderation: "1-1""1-1"64428
free.uk.legal: "1-1""1-1"275
which is not what I want.
Any help will be appreciated.
I have a file that looks like this:
$ head newsrc-news.eternal-september.org-test
nl.newsgroups.announce: 1-1329
free.uk.amateur-radio: 1-15497
uk.media.radio.misc: 1-456
uk.radio.amateur: 1-377688,377690,377692,377694-377697,377699,377701-377704 >uk.radio.amateur.moderated: 1-6432
uk.legal.moderated: 1-378428
comp.security.ssh: 1-3221
alt.comp.software.newsreaders: 1-481
uk.net.news.moderation: 1-64428
free.uk.legal: 1-275
I want to convert all the last part of the lines from 1-whatever to 1-1
In article <us9vka$fepq$[email protected]>,
Ottavio Caruso <[email protected]> wrote:
I have a file that looks like this:
$ head newsrc-news.eternal-september.org-test
nl.newsgroups.announce: 1-1329
free.uk.amateur-radio: 1-15497
uk.media.radio.misc: 1-456
uk.radio.amateur: 1-377688,377690,377692,377694-377697,377699,377701-377704 >> uk.radio.amateur.moderated: 1-6432
uk.legal.moderated: 1-378428
comp.security.ssh: 1-3221
alt.comp.software.newsreaders: 1-481
uk.net.news.moderation: 1-64428
free.uk.legal: 1-275
I want to convert all the last part of the lines from 1-whatever to 1-1
Two comments:
1) "sed" is almost never the right answer, regardless of what the
question is. AWK can do everything (with maybe one or two obscure
exceptions) that sed can do, and is a lot easier to use.
2) Why not just:
awk 'sub(/1-[0-9]+$/,"1-1");{ print "Line:",$0,"does not fit the expected pattern." > "/dev/stderr" }' yourfile
On 3/6/24 08:46, Ottavio Caruso wrote:
Any help will be appreciated.
Copying my sed version reply from alt.comp.software.thunderbird here for >completeness:
mv newsrc newsrc.backup
sed 's/:.*/: 1-1/' newsrc.backup > newsrc
Any help will be appreciated.
Am 06/03/2024 um 14:46 schrieb Ottavio Caruso:
I have a file that looks like this:
$ head newsrc-news.eternal-september.org-test
nl.newsgroups.announce: 1-1329
free.uk.amateur-radio: 1-15497
uk.media.radio.misc: 1-456
uk.radio.amateur:
1-377688,377690,377692,377694-377697,377699,377701-377704
uk.radio.amateur.moderated: 1-6432
uk.legal.moderated: 1-378428
comp.security.ssh: 1-3221
alt.comp.software.newsreaders: 1-481
uk.net.news.moderation: 1-64428
free.uk.legal: 1-275
[...]
Any help will be appreciated.
For posterity, Grant Taylor on alt.comp.software.thunderbird suggested
this and worked:
$ awk '{print $1, "1-1"}' newsrc-news.eternal-september.org-test > newsrc-news.eternal-september.org
Sorry for the noise. I never got to learn awk properly.
Julieta Shem <[email protected]> writes:
The book
The AWK Programming Language
Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
Addison-Wesley Publishing Company, 1988
ISBN 0-201-07981-X
is one of the most interesting books on programming ever written.
The second edition was published in 2024.
On 3/6/24 13:40, Janis Papanagnou wrote:
In this specific case of regular data you can simplify that to
awk '$2="1-1"' sourcefile > targetfile
Interesting.
I don't know that I've ever seen (re)defining a field value as part of
the script.
[...]
sed -i 's/:.*/: 1-1/' newsrc
In this specific case of regular data you can simplify that to
awk '$2="1-1"' sourcefile > targetfile
Ottavio Caruso <[email protected]> writes:
[...]
Sorry for the noise. I never got to learn awk properly.
The book
The AWK Programming Language
Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
Addison-Wesley Publishing Company, 1988
ISBN 0-201-07981-X
is one of the most interesting books on programming ever written.
(Along with SICP, HtDP and others.)
Julieta Shem <[email protected]> writes:
Ottavio Caruso <[email protected]> writes:
[...]
Sorry for the noise. I never got to learn awk properly.
The book
The AWK Programming Language
Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
Addison-Wesley Publishing Company, 1988
ISBN 0-201-07981-X
is one of the most interesting books on programming ever written.
(Along with SICP, HtDP and others.)
The second edition was published in 2024.
SICP is "Structure and Interpretation of Computer Programs" by Harold
Abelson and Gerald Jay Sussman with Julie Sussman.
HtDP is "How to Design Programs" by Matthias Felleisen, Robert Bruce
Findler, Matthew Flatt, and Shriram Krishnamurthi.
On 3/6/24 09:20, Kenny McCormack wrote:
sed -i 's/:.*/: 1-1/' newsrc
Agreed /if/ the sed that the OP is using supports `-i`.
My day job has me working across multiple platforms and try to do things
more consistently across the platforms.
For fucks sake, I know what awk is. I just never bothered learning it.
Just because you see a foreign name, you all expect we live in a cave.
You see that there's then (per default) only single delimiting spaces
left.
You can change that by delimiter OFS, e.g. OFS="\t" would place TABs
in between (but would not preserve the original spacing).
If you'd want to retain the previous spaces it would require some other
(not so trivial) handling.
Ottavio Caruso <[email protected]> writes:
Am 06/03/2024 um 21:50 schrieb Keith Thompson:
Julieta Shem <[email protected]> writes:
Ottavio Caruso <[email protected]> writes:The second edition was published in 2024.
[...]
Sorry for the noise. I never got to learn awk properly.
The book
The AWK Programming Language Alfred V. Aho, Brian W. Kernighan,
Peter J. Weinberger Addison-Wesley Publishing Company, 1988 ISBN
0-201-07981-X
is one of the most interesting books on programming ever written.
(Along with SICP, HtDP and others.)
SICP is "Structure and Interpretation of Computer Programs" by Harold
Abelson and Gerald Jay Sussman with Julie Sussman.
HtDP is "How to Design Programs" by Matthias Felleisen, Robert Bruce
Findler, Matthew Flatt, and Shriram Krishnamurthi.
For fucks sake, I know what awk is. I just never bothered learning it.
Just because you see a foreign name, you all expect we live in a cave.
What on Earth are you talking about? I didn't even notice your name.
I just expanded on what Julieta Shem wrote, and you somehow managed to
take offense. (I didn't know what HtDP means; I had to look it up, and
then I shared that information with the group.)
Someone having a bad day?
Ottavio Caruso <[email protected]> writes:
Am 06/03/2024 um 21:50 schrieb Keith Thompson:
Julieta Shem <[email protected]> writes:
Ottavio Caruso <[email protected]> writes:The second edition was published in 2024.
[...]
Sorry for the noise. I never got to learn awk properly.
The book
The AWK Programming Language
Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
Addison-Wesley Publishing Company, 1988
ISBN 0-201-07981-X
is one of the most interesting books on programming ever written.
(Along with SICP, HtDP and others.)
SICP is "Structure and Interpretation of Computer Programs" by
Harold
Abelson and Gerald Jay Sussman with Julie Sussman.
HtDP is "How to Design Programs" by Matthias Felleisen, Robert Bruce
Findler, Matthew Flatt, and Shriram Krishnamurthi.
For fucks sake, I know what awk is. I just never bothered learning it.
Just because you see a foreign name, you all expect we live in a cave.
What on Earth are you talking about? I didn't even notice your name.
I just expanded on what Julieta Shem wrote, and you somehow managed
to take offense. (I didn't know what HtDP means; I had to look it
up, and then I shared that information with the group.)
Sorry for the noise. I never got to learn awk properly.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 138:35:44 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,398 |