LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 06-16-2016, 12:07 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
SED question, can't delete first line from a file


Have a test file called file_sed.

Code:
Cygwin 
Unix 
Linux
Solaris
AIX
If using Special Character '^' because I want to remove the 1st line.

Code:
sed '^d' file_sed
I get

Code:
sed: -e expression #1, char 1: unknown command: `^'
I can use the Special Character '$' to remove the last line of the file.

Code:
sed '$d' file_sed 

Cygwin 
Unix 
Linux 
Solaris
It works.

I would think the '^' would not show the 1st line like the '$' character doesn't show the last line of the file.

Is my thinking correct?

Last edited by JockVSJock; 06-16-2016 at 12:13 PM.
 
Old 06-16-2016, 12:33 PM   #2
Mitt Green
Member
 
Registered: May 2014
Location: Europe
Posts: 199

Rep: Reputation: 116Reputation: 116
To simply remove the first line, try this:
Code:
sed -i -e "1d" file_sed
 
Old 06-16-2016, 12:52 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
$ is not a reg exp in this context, but match last line
man sed
Code:
The following address types are supported:

number      Match only the specified line number (which  increments  cumula-
            tively  across  files,  unless the -s option is specified on the
            command line).

...
$      Match the last line.
 
Old 06-16-2016, 12:53 PM   #4
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by Mitt Green View Post
To simply remove the first line, try this:
Code:
sed -i -e "1d" file_sed
Well...sure.

However I want to get familiar with SED's special characters, and I'm not understanding the why behind the '^' and the 1st line out of the file. And why it works with '$' with the last line.

thanks
 
Old 06-16-2016, 01:26 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would suggest you sit down with the man page and http://www.grymoire.com/Unix/Sed.html, then work your way through that entire web site as it covers all there is to know about sed
 
Old 06-16-2016, 07:02 PM   #6
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by grail View Post
I would suggest you sit down with the man page and http://www.grymoire.com/Unix/Sed.html, then work your way through that entire web site as it covers all there is to know about sed
Alright, I've booked marked that site. I have a number of them that I'm using to teach myself SED:

http://www.thegeekstuff.com/2009/09/...itute-command/

http://www.theunixschool.com/2013/02...csv-files.html

http://www.theunixschool.com/2012/06...e-line-or.html

http://www.theunixschool.com/2014/08...line-file.html


In the back of my mind, I'm wondering how long it will take to get good at SED. 90 days? 1 year?
 
Old 06-16-2016, 08:01 PM   #7
ThePenguinRules
LQ Newbie
 
Registered: Jun 2016
Posts: 3

Rep: Reputation: 0
...

Last edited by ThePenguinRules; 06-17-2016 at 09:47 PM.
 
Old 06-17-2016, 12:00 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I agree that it is the old 'how long is a piece of string' type question. I have understanding of the basics and a bit past but generally just use the site I listed when stuck
 
Old 06-17-2016, 01:55 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I'm definitely a 'one-liner' guy for sed.
If I want anything more complex I break out Perl because I used to do a LOT of work in Perl and I also find the regex docs a bit easier to follow (prob just familiarity I suppose...).
I highly recommend http://regex.info/book.html for all things regex ...
 
Old 06-17-2016, 02:09 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by JockVSJock View Post
In the back of my mind, I'm wondering how long it will take to get good at SED. 90 days? 1 year?
Whenever you have these thoughts, translate it thus
Code:
s/SED/CHESS/
Knowing the basic definitions doesn't make one "good".
 
Old 06-17-2016, 05:34 PM   #11
ThePenguinRules
LQ Newbie
 
Registered: Jun 2016
Posts: 3

Rep: Reputation: 0
...

Last edited by ThePenguinRules; 06-17-2016 at 09:47 PM.
 
Old 06-17-2016, 09:28 PM   #12
ThePenguinRules
LQ Newbie
 
Registered: Jun 2016
Posts: 3

Rep: Reputation: 0
...

Last edited by ThePenguinRules; 06-17-2016 at 09:47 PM.
 
  


Reply

Tags
sed, special character



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
how to delete a line from a file using sed nagaraj Linux - Newbie 2 09-02-2009 01:09 PM
Perl question: delete line from text file with duplicate match at beginning of line mrealty Programming 7 04-01-2009 06:46 PM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 04:41 PM

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

All times are GMT -5. The time now is 04:18 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