LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-05-2017, 09:45 AM   #1
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Rep: Reputation: Disabled
sed - skip (or delete) first n line than continue


Using sed, I would like to delete first n line from a file, than continue other commands.

I know
Quote:
sed 1,4d
, but its maybe not good for me, because I use complex command.
Quote:
sed 1,4d
means delete from 1st line to 4th line, than EXIT. I would like to delete the 1st 4 line, than continue....)

Now I use this commands:

Code:
sed -E 's/([a-zA-Z0-9.@]+):([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]+{2,4}):([0-9]+.[0-9]+.[0-9]+.[0-9]+):(.*)/\1 \2 \3/' pix.txt | sed 1,4d | less
pix.txt first n line:

Code:
BY @xxxxxxx THE SUN GOES DOWN…
twitter.com/xxxxxxxxx

concat_ws(':',name,email,ip_address,members_pass_hash,members_pass_salt)
USER1:username@pixarra.com:00.00.149.106:0fb88e5bf21eddd113cdaff1e0f5cfa2:-yh#]
USER2:username@shasta.com:00.106.00.148:9225fdc2aed7e7c8b372d15e52486a73:0aUBr
USER3:username@comcast.net:00.163.00.62:46e3c1ed2f8ffbadcc0bcdb17a4afe1a:pbx]q
Thanks for your help.
 
Old 09-05-2017, 11:59 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,507
Blog Entries: 3

Rep: Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814
Perhaps you mean this?

Code:
sed -E -e '1,4d; s/([a-zA-Z0-9.@]+):([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]+{2,4}):([0-9]+.[0-9]+.[0-9]+.[0-9]+):(.*)/\1 \2 \3/' pix.txt;
It will delete only the first four lines then process the rest with s///
 
1 members found this post helpful.
Old 09-05-2017, 12:05 PM   #3
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Perhaps you mean this?

Code:
sed -E -e '1,4d; s/([a-zA-Z0-9.@]+):([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]+{2,4}):([0-9]+.[0-9]+.[0-9]+.[0-9]+):(.*)/\1 \2 \3/' pix.txt;
It will delete only the first four lines then process the rest with s///

Thanks, it works.
I tried 1,4d without semicolon, with no success.
Quote:
-e
is important?
 
Old 09-05-2017, 12:08 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,507
Blog Entries: 3

Rep: Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814Reputation: 3814
No problem. sed is actually a programming language and 'd' is one of the commands. So is 's' So the semicolon is important to separate the individual commands.

Check the manual page

Code:
man sed
Using the -e to denote the script is a good idea if you start adding other options.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with sed command: if a line contains >2 colons (:) delete it and line above kmkocot Linux - Newbie 1 12-27-2011 08:51 AM
Sed command to skip first character of line which is slash se_ala Programming 6 08-05-2011 02:50 AM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM
SED - Delete line above or below as well as matching line... OldGaf Programming 7 06-26-2008 11:51 PM
trying to delete a line with sed deoren Linux - General 2 01-03-2005 09:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration