sed problem - last line of file deleted


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed problem - last line of file deleted
# 1  
Old 10-28-2008
sed problem - last line of file deleted

Hi,
I am simply trying to remove the header row from a file using sed, but I'm running into strange difficulties.
It seems that in addition to removing the first line, this command is also removing the last line (or more specifically, clearing the last line, since the line is still counted even though it's empty).
For what it's worth, I've included several versions of the sed command all exhibiting the same behavior.

Code:
sed '1 d' file
sed 1d file
sed '1d' file
sed '1,1 d' file

# 2  
Old 10-28-2008
Code:
more +2  file > newfile
mv newfile file

# 3  
Old 10-28-2008
Hammer & Screwdriver One of those sed commands looked ok

I like the tail command as the best method for this problem.

Code:
> cat file06
blah blah www.boston.com more blah
ha ha yech yes nope not yet tomorrow
today www.unix.com future www.unix.org
forever and ever sportsillustrated.cnn.com high

> sed '1d' file06
ha ha yech yes nope not yet tomorrow
today www.unix.com future www.unix.org
forever and ever sportsillustrated.cnn.com high

> tail +2 file06
ha ha yech yes nope not yet tomorrow
today www.unix.com future www.unix.org
forever and ever sportsillustrated.cnn.com high

# 4  
Old 10-28-2008
From what I have hear for sed and others to work correctly there MUST be a carrage return on the last line, other wise it cuts off.
# 5  
Old 10-28-2008
Quote:
Originally Posted by Ikon
From what I have hear for sed and others to work correctly there MUST be a carrage return on the last line, other wise it cuts off.
Interesting. That could very well explain it.

Thanks for the input everyone else. I now have plenty of workarounds.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

sed delete but save deleted output into other file

Hi guys, I am currently using this to save first 50 lines into top50.txt and delete them from list.txt ... it's 2 commands: head -n 50 list.txt > top50.txt && sed -i "1,50 d" list.txt I want to change that so it's 1 command - whereby sed removes the first 50 lines as above but that which is... (3 Replies)
Discussion started by: holyearth
3 Replies

3. Shell Programming and Scripting

Last line gets deleted

I was using the following option to clean up the ^M characters in a file that was FTPed from Windows: - dos2unix - sed 's/^M//g' The ^M characters are removed but the last line is also getting removed. Any idea why this is happening. Satish (2 Replies)
Discussion started by: vskr72
2 Replies

4. Shell Programming and Scripting

Replace pattern with deleted line?

If I have this: perl -pne 's/img_onload.{8}//g' How would I do to instead of replacing img_onload.{8} with "nothing", get "nothing" to be a deleted line? Kind of the opposite to \n. (2 Replies)
Discussion started by: KidCactus
2 Replies

5. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

6. Shell Programming and Scripting

Another parsing line awk or sed problem

Hi, After looking on different forums, I'm still in trouble to parse a parameters line received in KSH. $* is equal to "/AAA:111 /BBB:222 /CCC:333 /DDD:444" I would like to parse it and be able to access anyone from his name in my KSH after. like echo myArray => display 111 ... (1 Reply)
Discussion started by: RickTrader
1 Replies

7. Shell Programming and Scripting

Sed line concatenation problem

I have a somewhat bizarre problem when trying to concatenate lines in a file. Using cat file.txt | sed -e :a -e '/$/N;s/\n/ /;ta' the output in file.txt should go from 1 2 3to 1 2 3 instead I only get the last line or 3. I find that if I open the file in gedit and hit delete in front of every... (7 Replies)
Discussion started by: pluto7777
7 Replies

8. UNIX for Dummies Questions & Answers

logging deleted records by sed

Hi, I want to use the sed command to delete some lines in a file and I was wondering whether there is a possibility of knowing which lines are deleted, or at least which line numbers. Thanks (4 Replies)
Discussion started by: vanagreg
4 Replies

9. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

10. UNIX for Dummies Questions & Answers

Sed new line problem

Hi all, I've searched the web and this forum for this but not had any luck. I'm trying to use sed so when it finds a space it will insert a new line. What i have is a file containing .e.g 1 2 4 7 9 and want it to look like 1 2 4 7 9 I've tried: more test2 | sed 's/ /\\n/g'... (1 Reply)
Discussion started by: Cordially
1 Replies
Login or Register to Ask a Question