0

I would like to replace first line with empty string in shell script?

For example:

Input

Skipping HTTPS certificate checks altogether. Note that this is not secure at all. 
Line 2 ......
Line 3 ......

Output

Line2
Line3

What Unix command I can use to perform same? Any Idea?

3
  • 2
    your input and output are from files or command outputs? Commented Jul 21, 2015 at 9:27
  • Looks like that first line is there for a reason! Anyway, do you want to delete the contents of the line or remove it altogether? What have you tried here and where are you stuck? Commented Jul 21, 2015 at 9:44
  • This is from command output. Commented Jul 21, 2015 at 10:12

3 Answers 3

2

you can use below also

yourcommand | awk 'NR>1'

or

yourcommand | tail -n+2
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any problem in #1? Let me know the issue. I will correct it.
I didn't try first one. I just used second one.
1

if it's in a file, you can use this to delete the first line :

sed -i '1d' ../file.txt

1 Comment

Thanks for the response. Actually I was looking to apply it on string which is returned by command.
0

Do you mean, that you want Output to be basically equal to Input, but the first line being delted? This is is done with the Unix command 'tail'.

From the man page of tail:

    -n, --lines=K
          output the last K lines, instead of the last 10; or use -n +K to output starting with
          the Kth

7 Comments

My input is coming from another command and I want to delete first line from that input.
this is more a comment than an answer
Many things: answer normally explain how to do something and then do it, eventually showing some kind of output. This just a comment about how to do it.
I think it is best to provide a complete answer. Otherwise many questions could be answered with a mere "check man -command-"
This is a true point. Note that many questions become closed exctly because of that. See How to Ask for more info. Then, as a good question can be "assumed", a good answer can come. Interesting infos: Why and how are some answers deleted? and How do I write a good answer?. Happy experience in SO!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.