Complete.Org: Mailing Lists: Archives: linux-help: March 2003:
[linux-help] Re: Regular expression with grep
Home

[linux-help] Re: Regular expression with grep

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: Regular expression with grep
From: Jeff Vian <jvian10@xxxxxxxxxxx>
Date: Wed, 26 Mar 2003 18:31:55 -0600
Reply-to: linux-help@xxxxxxxxx

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:bbales@xxxxxxx]
>Sent: Tuesday, March 25, 2003 9:56 PM
>To: linux-help@xxxxxxxxx
>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 linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]