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 04-10-2008, 10:10 AM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Rep: Reputation: 83
sed adding an extra \n ???


Hya,

Problem is it looks like that a sed script is adding an extra \n.

Background.
I have a bunch of files, format looks like

line 1: definiton
line 2-end: data (only [a-zA-Z]

and when data is bad, second line contains several X's only.

In short
good data files looks like
Code:
:This is an example of good file.
ADVRGBFGTHTFGRGRGETYHSBSHT
FVGRGBFBRHHGDFGHRHHFBDFGGD
...
SDFSDFSAFAS
bad data looks like
Code:
:This is an example for bad file.
XXXXX
and number of X is undefined (mostly under 20).

I wrote a sed script (filter) to eliminate bad data file, which looks like
Code:
#!/bin/sed -nf 
1 H
2 {     H
        s/^X*$/NG/
        T n
        Q
        :n 
        x
        p
        }
3,$ {   p
        }
When numerous input files are piped into the script above, it looks like that an additional \n between files is added.

I need to find where bug is...

I appreciate any help.

Happy Penguins!
 
Old 04-10-2008, 02:06 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
If you want to prevent a leading newline, you can just change:
Code:
1 H
to
Code:
1 h
 
Old 04-10-2008, 06:58 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
you can use an alternative that keeps it simple.
Code:
awk 'NR==2 && /^XXXXX/{next}1' file
 
  


Reply

Tags
pipe, script, sed


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
sed error message:extra characters after the command wmh830621 Programming 4 08-14-2006 07:13 PM
adding an extra harddrive... what FS to use and how to use the drive? drawagoat Linux - Newbie 3 08-11-2006 01:02 PM
Adding extra sections to apt-get cluelessnewb Linux - Software 2 07-31-2006 08:31 PM
sed error message: extra characters after the command. nano_mag Linux - General 3 05-15-2005 01:00 AM
adding extra repositories? KezzerDrix Mandriva 1 04-27-2005 09:55 AM


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