Thread View: comp.unix.shell
5 messages
5 total messages
Started by Brian J. Smith
Fri, 30 Nov 1990 05:28
How to strip A NEWLINE
Author: Brian J. Smith
Date: Fri, 30 Nov 1990 05:28
Date: Fri, 30 Nov 1990 05:28
43 lines
2339 bytes
2339 bytes
When TFM fails, when all the books I have fail, I run to netland. I have searched high and low for the answer on how to strip a NEWLINE charactor from a file. Well not really a NEWLINE char, but a ":\\\n" (colon,back-slash,newline). I have tried useing sed with: sed 's/:\\\n//' file and using the RS variable in awk, but to no avail. sed will remove the colon and the back-slash, but not the newline. Here is the section of code that I am playing with. # ps301d|bigps|qms|QMS-2210 in E301D:\ :lp=/dev/ttyb:sd=/var/spool/ps301d:\ :af=/var/adm/ps301d.acct:lf=/var/spool/ps301d/errs:\ :br#9600:rw:fc#0000374:fs#0000003:xc#0:xs#0040040:\ :mx#0:rg=printer:sf:sh:\ :if=/local/lib/ps/psif:of=/local/lib/ps/psof:\ :cf=/cis/reef/wp42/bin/wplpr:df=/local/lib/ps/psdf:\ :gf=/local/lib/ps/psgf:nf=/local/lib/ps/psnf:\ :rf=/local/lib/ps/psrf:tf=/local/lib/ps/pstf:\ :vf=/local/lib/ps/psvf: # This is what I want the file to look like after the (colon,back-slash,newline) has been striped. As you can see what I really want is to strip a (colon,back-slash,newline,tab), but if someone could just get rid of that darn newline for me I would be *very* happy. # ps301d|bigps|qms|QMS-2210 in E301D:lp=/dev/ttyb:sd=/var/spool/ps301d:af=/var/adm/ps301d.acct:lf=/var/spool/ps301d/errs:br#9600:rw:fc#0000374:fs#0000003:xc#0:xs#0040040:mx#0:rg=printer:sf:sh:if=/local/lib/ps/psif:of=/local/lib/ps/psof:cf=/cis/reef/wp42/bin/wplpr:df=/local/lib/ps/psdf:gf=/local/lib/ps/psgf:nf=/local/lib/ps/psnf:rf=/local/lib/ps/psrf:tf=/local/lib/ps/pstf:vf=/local/lib/ps/psvf: # I know that perl can most likely solve this probelm nicely, so I am willing to hear of any responses, but for standardaztion I would like to use only standard unix filters. Sorry Larry. -- Brian J. Smith Work: 904-392-1183 CIS Sys Admin Staff 301 CSE Building bjs@cis.ufl.edu Univ of Florida, 32612
Re: How to strip A NEWLINE
Author: Philippe Deschamp
Date: Fri, 30 Nov 1990 17:25
Date: Fri, 30 Nov 1990 17:25
35 lines
1738 bytes
1738 bytes
In article <25665@uflorida.cis.ufl.EDU>, bjs@reef.cis.ufl.edu (Brian J. Smith)
writes:
|> I have searched high and low for the answer on how to strip a NEWLINE
|> charactor from a file. Well not really a NEWLINE char, but a ":\\\n"
|> (colon,back-slash,newline). I have tried useing sed with:
|>
|> sed 's/:\\\n//' file
|>
|> and using the RS variable in awk, but to no avail. sed will remove
|> the colon and the back-slash, but not the newline.
The key is that "\n Matches a NEWLINE embedded in the pattern space." (from
sed(1)). So you must embed a NL in the pattern space! With the "N" command,
for example. The following does what you asked for, I should think:
sed -e ': more
/:\\$/{
N
s/:\\\n *:*/:/
t more
}'
You can read this as
while the current line ends with ":\", do
append next line to current, with NL in between,
get rid of "\", the NL and some TABs and superfluous ":"s
end while
Have fun! Sed is a wonderful tool, as long as you don't overuse it...
Philippe Deschamp.
Tlx: 697033F Fax: +33 (1) 39-63-53-30 Tel: +33 (1) 39-63-58-58
Email: Philippe.Deschamp@nuri.inria.fr || ...!inria!deschamp
Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France
Re: How to strip A NEWLINE
Author: Don Bolton
Date: Fri, 30 Nov 1990 21:00
Date: Fri, 30 Nov 1990 21:00
53 lines
2765 bytes
2765 bytes
In article <25665@uflorida.cis.ufl.EDU> bjs@reef.cis.ufl.edu (Brian J. Smith) writes:
>
>When TFM fails, when all the books I have fail, I run to netland.
>
>I have searched high and low for the answer on how to strip a NEWLINE
>charactor from a file. Well not really a NEWLINE char, but a ":\\\n"
>(colon,back-slash,newline). I have tried useing sed with:
>
> sed 's/:\\\n//' file
>
>and using the RS variable in awk, but to no avail. sed will remove
>the colon and the back-slash, but not the newline.
>
>Here is the section of code that I am playing with.
Not taking time to play with it but.
a printf statement in awk will not input a newline unless you specify
one.
{ printf("%s|%s|%s|%s|%s|%s ", $1, $2, $3, $4, $5, $6) }
(assuming you want the pipe char as a seperator)
>
>#
>ps301d|bigps|qms|QMS-2210 in E301D:\
> :lp=/dev/ttyb:sd=/var/spool/ps301d:\
> :af=/var/adm/ps301d.acct:lf=/var/spool/ps301d/errs:\
> :br#9600:rw:fc#0000374:fs#0000003:xc#0:xs#0040040:\
> :mx#0:rg=printer:sf:sh:\
> :if=/local/lib/ps/psif:of=/local/lib/ps/psof:\
> :cf=/cis/reef/wp42/bin/wplpr:df=/local/lib/ps/psdf:\
> :gf=/local/lib/ps/psgf:nf=/local/lib/ps/psnf:\
> :rf=/local/lib/ps/psrf:tf=/local/lib/ps/pstf:\
> :vf=/local/lib/ps/psvf:
>#
>
>This is what I want the file to look like after the (colon,back-slash,newline)
>has been striped. As you can see what I really want is to strip a
>(colon,back-slash,newline,tab), but if someone could just get rid of that
>darn newline for me I would be *very* happy.
>
>#
>ps301d|bigps|qms|QMS-2210 in E301D:lp=/dev/ttyb:sd=/var/spool/ps301d:af=/var/adm/ps301d.acct:lf=/var/spool/ps301d/errs:br#9600:rw:fc#0000374:fs#0000003:xc#0:xs#0040040:mx#0:rg=printer:sf:sh:if=/local/lib/ps/psif:of=/local/lib/ps/psof:cf=/cis/reef/wp42/bin/wplpr:df=/local/lib/ps/psdf:gf=/local/lib/ps/psgf:nf=/local/lib/ps/psnf:rf=/local/lib/ps/psrf:tf=/local/lib/ps/pstf:vf=/local/lib/ps/psvf:
>#
>
>I know that perl can most likely solve this probelm nicely, so I am willing to
>hear of any responses, but for standardaztion I would like to use only standard
>unix filters. Sorry Larry.
>--
>Brian J. Smith Work: 904-392-1183
>CIS Sys Admin Staff 301 CSE Building
>bjs@cis.ufl.edu Univ of Florida, 32612
Re: How to strip A NEWLINE
Author: Stephen M. Kennedy
Date: Fri, 30 Nov 1990 21:32
Date: Fri, 30 Nov 1990 21:32
23 lines
1058 bytes
1058 bytes
In article <1781@seti.inria.fr>, deschamp@minos.inria.fr (Philippe Deschamp) writes:
> [sed script to remove \<new-line>]
> sed -e ': more
> /:\\$/{
> N
> s/:\\\n *:*/:/
> t more
> }'
Anybody got any ideas on how to make this script work on input of the form
one:\
two:\
three:\
oops:\
<EOF>
Currently, the N command aborts and the script produces no output on the
last iteration; I'd like it to just act as if the last \ wasn't there.
Steve Kennedy
smk@cbosgd.att.com
smk@cbnews.att.com
Re: How to strip A NEWLINE
Author: WU SHI-KUEI
Date: Mon, 03 Dec 1990 16:23
Date: Mon, 03 Dec 1990 16:23
6 lines
678 bytes
678 bytes
tr -d '\012' < file will strip newlines. Use 'sed' first if removing other stuff, e.g. sed 'whatever' file | tr -d '\012'
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads