LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-19-2005, 10:58 AM   #1
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,822

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
Question weird sed output


i am getting this weird output from sed. i am expecting it to only print out line 5:
gouki

but it is printing everything with line 5 duplicated. here is the example with system info:

schneidz@lq> uname -a -M -p
AIX lq 2 5 00yyyyyy4C00 powerpc IBM,7040-671
schneidz@lq> cat lq.txt
hello
world
l33t
h4x0r
gouki
chun-li
schneidz@lq> sed 5p lq.txt
hello
world
l33t
h4x0r
gouki
gouki
chun-li


let me know what you find out?
thanx
schneidz
 
Old 05-19-2005, 11:03 AM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
This appears to be a known issue.
From http://www.linuxselfhelp.com/gnu/sed...ter/sed_3.html:

Quote:
`p'
Print out the pattern space (to the standard output). This command is usually only used in conjunction with the -n command-line option. Note: some implementations of SED, such as this one, will double-print lines when auto-print is not disabled and the p command is given. Other implementations will only print the line once. Both ways conform with the POSIX.2 standard, and so neither way can be considered to be in error. Portable SED scripts should thus avoid relying on either behavior; either use the -n option and explicitly print what you want, or avoid use of the p command (and also the p flag to the s command).
Therefore,
Code:
me@localhost:~$ sed 5p lq.txt
hello
world
l33t
h4x0r
gouki
gouki
gouki
chun-li
me@localhost:~$ sed -n 5p lq.txt
gouki
HTH!
 
Old 05-19-2005, 11:08 AM   #3
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,822

Original Poster
Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
thx rosebud (not sure if that is a citizen kane or h2g2 reference).

works for me too.
 
Old 05-19-2005, 11:16 AM   #4
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
heh...unfortunately neither- I'd feel a lot less silly if it were a nice explainable reference.
Sadly it's just a carryover from an old email address that I used when I was in high school, and I'm just sort of used to typing it.

*shrug*
 
  


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
How to process ping output with sed? Griffon26 Linux - General 5 08-30-2009 04:16 PM
Weird DF Output Mr_Munkey Linux - General 4 03-09-2005 09:11 AM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 07:54 PM
weird sed problems C++freak Slackware 5 08-04-2003 04:00 PM
weird sed problem bartgymnast Linux - General 1 02-25-2003 03:31 PM


All times are GMT -5. The time now is 03:51 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration