I can't search for a particular string, since they're all very similar, but I'd like something simple to chop out the first 4 lines in a file.
They're all variable length too. I've had a think about perl, and it all seems harder than I thought, but I'd like to do it in Perl, AWK or a shell command if possible.
Does anybody have a simple way of doing this?
Using the sed Command Removing the first line from an input file using the sed command is pretty straightforward. The sed command in the example above isn't hard to understand. The parameter '1d' tells the sed command to apply the 'd' (delete) action on line number '1'.
Delete lines or connectorsClick the line, connector, or shape that you want to delete, and then press Delete. Tip: If you want to delete multiple lines or connectors, select the first line, press and hold Ctrl while you select the other lines, and then press Delete.
Scanner fileScanner = new Scanner(myFile); fileScanner. nextLine(); This will return the first line of text from the file and discard it because you don't store it anywhere.
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
tail -n+2 filename
Will skip the first line in filename
and output it to stdout. The -n+2
option means to start outputting lines beginning with the second line.
Of course you can substitute 2 with whatever number you need (your title and actual question content say first and fifth, respectively).
sed
is the simplest. To delete the first line of a file, do:
sed '1d' file.txt
Or, to remove the first four lines, do:
sed '1,4d' file.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With