Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing lines from files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi..
I FTP'd a file from NT box to the UNIX box. The files have a CR/LF character which has been stripped off. There is an additional formfeed character in the file...Its just a collection of 3-4 blank lines. Actually, these lines look like a tab to me when I scroll down in the vi editor.

Can anyone suggest how to strip off these blank lines.
 
this isn't the answer to your question,
but did you do the ascii command before
you did a get or put duing ftp?

ex:
ftp hostname
ascii
put filename

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
 
Yes I did include the "ascii" command in the ftp script

Thanx
 
type this in command mode in vi

:%s/^V^M//g

Basically your are removing the ctrl-M character from the file. You will have to type ctrl-V before typing ctrl-M.

Mohan
 
Alternatively, if your machine supports dos2unix, use that:

dos2unix <orig_file> <new_file>

HTH.
 
I would do it in two steps:

- precisely defining the undesirable characters, by using command od -c filename.

Depending on these characters, you´ll need to see them in octal or hexadecimal, so also consider the variants &quot;od -oc <filename>&quot; or &quot;od -xc <filename>&quot; .

- changing them for something more desirable, like spaces, using command tr.

For example, Microsoft´s end-of-lines are comprised of two bytes , carriage-return and new-line ( \r \n , octal \015\005 ). Changing the \r for space (octal \020) satisfies most of the cases , and the syntax below can do the thing :

tr &quot;\r&quot; &quot; &quot; <myfile
OR
tr &quot;\015&quot; &quot;\020&quot; <myfile

I suggest you to take a look at man tr , it has some other interesting features . Maybe -d , for example , will fit better your needs.

tr can perform several of the easiest tasks people normally relay to awk and sed, but it´s much easier to learn. Good for lazy or too-busy guys , like me... ;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top