2

I am incorporating SED into a Windows batch file. I've got it working for deleting the first seven lines of a text file:

SED "1,7d"

However, I'd like to make it a smarter statement. Essentially, I have a huge text file that I want to lop off the first few lines…and keep everything from the column heading and below. The first line of text I want is line 8 and is "Year" with quotes.

I've tried the following and I'm receiving an error in the command window (running the batch file):

SED "1,/"Year"/!d"

I am putting in the input and output files after the expression.

closed as off-topic by slm, Anthon, Bernhard, terdon, jasonwryan Jan 1 '14 at 17:52

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you have an awk to use? awk '/Year/{found=1}found'. And what do you mean "output files after the expression"? sed only takes input files on the command line – Kevin May 1 '13 at 20:47
  • 2
    “I'm receiving an error”: so what's the error? And why are you asking about a Windows script on a Unix site? I suggest reposting on Super User, with the error message. – Gilles May 1 '13 at 23:23
  • I'm not familiar with awk. What I meant by output files is that after this code I have the target.txt > output.txt – user38324 May 2 '13 at 13:19
  • 2
    This question appears to be off-topic because your problem appears to be at least partly with quoting issues with Microsoft's cmd.exe shell. SuperUser would be a better site for this. – Mat Jun 30 '13 at 4:27
  • 3
    This question appears to be off-topic because your problem appears to be at least partly with quoting issues with Microsoft's cmd.exe shell. SuperUser would be a better site for this. – Anthon Jan 1 '14 at 15:41
0

I don't know much about the quoting behaviour on windows, but you could try this:

SED '1,/"Year"/!d' 
  • This also did not work, with a different error message: SED: -e expression #1, char 1: Unknown command "''" – user38324 May 2 '13 at 13:26
  • I think you really need to install CYGWIN, and use the sed that comes with it. That error message makes no sense to me as it indicates that your sed thinks of a single quote as a command. – tink May 2 '13 at 17:42
  • Yeah, that's how quoting on Windows works. Since this is a Unix site, it might be best to simply close the question as off-topic ...? – tripleee Jun 29 '13 at 8:30
  • As far as I know, cmd doesn't give a dime on quoting. (For example echo "Hello" outputs "Hello", including the quotes.) So I would try simply sed 1,/"Year"/!d, without outer quotes. – manatwork Jun 29 '13 at 11:33
0

This wiki article indicates inner quotes should be tripled:

SED "1,/"""Year"""/!d"

untested.

  • I tried this and it did not work. – user38324 May 2 '13 at 13:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.