Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Shell Scripts - removing line endings

Thread Tools
 
Search this Thread
 
Old 15 October 2009, 05:14 PM
  #1  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default Shell Scripts - removing line endings

I'm using bash/sh and have a script which does the following:

touch NameOfThefile
echo "Data In the File" >> NameOfThefile

The resulting file is used by an application, and it reads the data from the file and does something with it. However, the app requires that the data is on a single line with no new line or carriage return characters at the end and the echo command is adding a newline/carriage return to the end of the file.

So the question is, how can I preserve the text in the file but remove the line ending? Is there another way, via shell, to write data to a file that would not result in the line ending being put there, if so, how do I do it?

Thanks in advance.
Old 17 October 2009, 03:14 PM
  #2  
Jonnys3
Scooby Regular
 
Jonnys3's Avatar
 
Join Date: May 2008
Location: Derbyshire
Posts: 1,260
Received 3 Likes on 3 Posts
Default

Simple script to remove all eol markers from a file:

#!/bin/bash
#
# remove_eol.sh - script to remove eol markers from file
#
INPUT="NameOfThefile"
while read line
do
echo -n ${line}
done < ${INPUT}


When running the script you will need to redirect the output to a new filename otherwise it will simply write to screen:

remove_eol.sh > NewFilename

Hope this helps.

Jonny.

Last edited by Jonnys3; 17 October 2009 at 03:21 PM.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
Pro-Line Motorsport
Car Parts For Sale
48
21 July 2017 09:50 PM
Pro-Line Motorsport
Car Parts For Sale
11
21 November 2015 06:08 PM
Pro-Line Motorsport
Car Parts For Sale
0
27 September 2015 11:23 AM
S600HBY
Subaru Parts
0
25 September 2015 09:46 AM



Quick Reply: Shell Scripts - removing line endings



All times are GMT +1. The time now is 08:01 AM.