Re: Regular expression with grep

Jeff Vian <[email protected]>
Newsgroups gmane.org.user-groups.aclug.linux-help
Message-ID <[email protected]>
an easier tool to change the lines having the DOS ending of CR/LF is the 
command
'dos2unix' in my version of Linux   It parses each line of a file and 
converts the structure to end with the LF only that is standard in unix.

Then a simple  'cat file | sed -e s/ $//g > newfile would strip /all/ 
 spaces from the end of lines where they exist.

Wilner, Alden wrote:

>Have you tried "sed s/.$//" ?
>

This removes the last char on the line before the LF withour regard for 
what it is, and may remove a character you want to keep unless you have 
exhaustively confirmed every line has an extra character at that position.

>Since every line has EITHER an extra space OR an extra CR character, you can
>just use the wildcard.
>Obviously if some lines just have a word with a LF following it, this will
>not work. Then you would want to consider something
>like "s/[a-zA-z]$/&!/" to add a character to the lines that don't already
>have one.
>-----Original Message-----
>From: bruce [mailto:[email protected]]
>Sent: Tuesday, March 25, 2003 9:56 PM
>To: [email protected]
>Subject: [linux-help] Regular expression with grep
>
>
>I have a large file which is a concatination and sort of two files, one 
>from msdos and the other from linux.  Each line is a single word.  grep 
>doesn't work as I expected on this file.  Examination revealed some 
>lines end with "(space)LF" and some end with "CR/LF".  
>
>I want to eliminate the CR and the space.  I tried
>cat foo |sed s/\x0d\x0a/\x0a/ and it didn't do anything.  A test run of 
>cat foo |grep \x0d finds nothing.  Neither does 
>cat foo |grep \x61.  cat foo |grep a finds lots of words with an "a" in 
>them.
>
>I tried many combinations of quotes, parentheses, braces, brackets, 
>single quotes and nothing works with grep or sed.
>
>Several books and a search of the web didn't turn up anything useful.  
>Any help?
>bruce
>  
>


-- This is the [email protected] list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.