You are not logged in.

#1 2014-09-26 23:34:08

geo909
Member
Registered: 2008-09-07
Posts: 309

[SOLVED} Script that deletes a certain type of lines from a text file

Hi all,

I have a favour to ask.. I need the following to make my life easier when I enter a gazillion of grades
for tutorials and tests of my students.

I need a script that deletes every line from a text file, if both of these hold:
1) The line does not end with a dash ( - )
2) The line is not the first one.

Then I need a second script that deletes every line that ends with a dash.

I'll be honest with you, I haven't tried to find out how to do it.. At this point my priority is to submit those grades faster, not to learn sed,
so I'm asking it as a favour, in case anybody has a couple of one-liners on the top of their heads.

Thank you in advance.

Last edited by geo909 (2014-09-27 00:08:40)

Offline

#2 2014-09-26 23:40:02

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,517

Re: [SOLVED} Script that deletes a certain type of lines from a text file

geo909 wrote:

2) The life is not the first one.

Dag nab it, I could've have fun with that one.

geo909 wrote:

in case anybody has a couple of one-liners on the top of their heads.

We can always come up with one-liners.

So what a sed/awk sort of thing?


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#3 2014-09-26 23:40:16

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED} Script that deletes a certain type of lines from a text file

sed '1b; /-$/!d' file
sed '/-$/d' file

This silver ladybug at line 28...

Offline

#4 2014-09-26 23:58:12

geo909
Member
Registered: 2008-09-07
Posts: 309

Re: [SOLVED} Script that deletes a certain type of lines from a text file

nomorewindows wrote:
geo909 wrote:

2) The life is not the first one.

Dag nab it, I could've have fun with that one.

Hahaha, yeah, that's a pretty spiritual script I was looking for!

lolilolicon wrote:
sed '1b; /-$/!d' file

sed '/-$/d' file

That's exactly what I needed. Thanks, you saved lots of my time!

Offline

Board footer

Powered by FluxBB