Remove newlines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove newlines
# 15  
Old 02-28-2014
Here you go...
Longhand using _old_style_ bash scripting...
Code:
#!/bin/bash
# rm_nl.sh
# Get the string into a FileName including the odd single quote...
echo -e -n '10 Special Projects bangaram 0 0
10 Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) bangaram 0 0
10 Complience with SVCCL bangaram 0 0
10 "Release of incentives / commission to all channel partners.
" bangaram 0 0
10 Timely processing of sales orders to channel partners bangaram 0 0
10 Balance sheet Reviwe bangaram 0 0
10 Ensuring Critical Reconciliation on monthly basis. (IN-GL) bangaram 0 0
10 "Timely & accurate closure of Accounts.
" bangaram 0 0
10 Timely calculation & releasing of Monthly prepaid related commissions & Postpaid ( AEO'"'"'s) bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Visit bangaram 0 0
11 Prospect bangaram 0 0
11 Collection bangaram 0 0
11 Revenu bangaram 0 0
11 New Sales bangaram 0 0
11 Yellow Belt Project bangaram 0 0
11 CAG Score bangaram 0 0
11 Revenue Focus bangaram 0 0
12 Revenue Focus bangaram 0 0
12 Performance Score card bangaram 0 0
12 Performance Score card bangaram 0 0
12 Airtel Stores Management bangaram 0 0
12 CSMM bangaram 0 0' > /tmp/FileName
cat < /tmp/FileName
tr -d '\n' < /tmp/FileName > /tmp/NewFileName
echo ""
echo ""
cat < /tmp/NewFileName
echo ""
echo ""
mynewfile=""
nl=0
read -d '' -r myfile < /tmp/NewFileName
while true
do
	if [ $nl -ge $[ ( ${#myfile} - 1 ) ] ]
	then
		break
	fi
	if [ "${myfile:$nl:3}" == "0 0" ]
	then
		mynewfile=$mynewfile${myfile:$nl:3}$'\n'
		nl=$[ ( $nl + 3 ) ]
	else
		mynewfile=$mynewfile${myfile:$nl:1}
		nl=$[ ( $nl + 1 ) ]
	fi
done
echo "$mynewfile" > /tmp/File
cat < /tmp/File

Results...
Code:
Last login: Fri Feb 28 19:09:19 on ttys000
AMIGA:barrywalker~> chmod 755 rm_nl.sh
AMIGA:barrywalker~> ./rm_nl.sh
10 Special Projects bangaram 0 0
10 Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) bangaram 0 0
10 Complience with SVCCL bangaram 0 0
10 "Release of incentives / commission to all channel partners.
" bangaram 0 0
10 Timely processing of sales orders to channel partners bangaram 0 0
10 Balance sheet Reviwe bangaram 0 0
10 Ensuring Critical Reconciliation on monthly basis. (IN-GL) bangaram 0 0
10 "Timely & accurate closure of Accounts.
" bangaram 0 0
10 Timely calculation & releasing of Monthly prepaid related commissions & Postpaid ( AEO's) bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Visit bangaram 0 0
11 Prospect bangaram 0 0
11 Collection bangaram 0 0
11 Revenu bangaram 0 0
11 New Sales bangaram 0 0
11 Yellow Belt Project bangaram 0 0
11 CAG Score bangaram 0 0
11 Revenue Focus bangaram 0 0
12 Revenue Focus bangaram 0 0
12 Performance Score card bangaram 0 0
12 Performance Score card bangaram 0 0
12 Airtel Stores Management bangaram 0 0
12 CSMM bangaram 0 0

10 Special Projects bangaram 0 010 Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) bangaram 0 010 Complience with SVCCL bangaram 0 010 "Release of incentives / commission to all channel partners." bangaram 0 010 Timely processing of sales orders to channel partners bangaram 0 010 Balance sheet Reviwe bangaram 0 010 Ensuring Critical Reconciliation on monthly basis. (IN-GL) bangaram 0 010 "Timely & accurate closure of Accounts." bangaram 0 010 Timely calculation & releasing of Monthly prepaid related commissions & Postpaid ( AEO's) bangaram 0 011 Opex Spend on communication activites bangaram 0 011 Opex Spend on communication activites bangaram 0 011 Visit bangaram 0 011 Prospect bangaram 0 011 Collection bangaram 0 011 Revenu bangaram 0 011 New Sales bangaram 0 011 Yellow Belt Project bangaram 0 011 CAG Score bangaram 0 011 Revenue Focus bangaram 0 012 Revenue Focus bangaram 0 012 Performance Score card bangaram 0 012 Performance Score card bangaram 0 012 Airtel Stores Management bangaram 0 012 CSMM bangaram 0 0

10 Special Projects bangaram 0 0
10 Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) bangaram 0 0
10 Complience with SVCCL bangaram 0 0
10 "Release of incentives / commission to all channel partners." bangaram 0 0
10 Timely processing of sales orders to channel partners bangaram 0 0
10 Balance sheet Reviwe bangaram 0 0
10 Ensuring Critical Reconciliation on monthly basis. (IN-GL) bangaram 0 0
10 "Timely & accurate closure of Accounts." bangaram 0 0
10 Timely calculation & releasing of Monthly prepaid related commissions & Postpaid ( AEO's) bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Opex Spend on communication activites bangaram 0 0
11 Visit bangaram 0 0
11 Prospect bangaram 0 0
11 Collection bangaram 0 0
11 Revenu bangaram 0 0
11 New Sales bangaram 0 0
11 Yellow Belt Project bangaram 0 0
11 CAG Score bangaram 0 0
11 Revenue Focus bangaram 0 0
12 Revenue Focus bangaram 0 0
12 Performance Score card bangaram 0 0
12 Performance Score card bangaram 0 0
12 Airtel Stores Management bangaram 0 0
12 CSMM bangaram 0 0

AMIGA:barrywalker~> _

EDIT:
Highly annoyed; where have all the tabs come from?

Last edited by wisecracker; 02-28-2014 at 04:15 PM.. Reason: See above...
# 16  
Old 02-28-2014
Quote:
Originally Posted by wisecracker
Highly annoyed; where have all the tabs come from?
They were always there but they weren't obvious before, because of the lacking code tags..

Last edited by Scrutinizer; 02-28-2014 at 04:33 PM..
# 17  
Old 02-28-2014
Hi Scrutinizer...
Thanks for that...
Here is a primitive starter version for line numbers 10 to 19.
Longhand using _old_style_ bash scripting...
Code:
#!/bin/bash
# rm_newline.sh
echo -e '10,"Special Projects,bangaram",0,,0
10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation)",	bangaram,0,,0
10,"Complience with SVCCL",	bangaram,	0,,	0
10,	"Release of incentives / commission to all channel partners.
",	bangaram,	0,,	0
10,"Timely processing of sales orders to channel partners",	bangaram,	0,,	0
10,"	Balance sheet Reviwe", bangaram,	0,,	0
10,"	Ensuring Critical Reconciliation on monthly basis. (IN-GL)",	bangaram,	0,,	0
10,	"Timely & accurate closure of Accounts.
",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram	,0,,	0' > /tmp/FileName
cat < /tmp/FileName
tr -d '\n' < /tmp/FileName > /tmp/NewFileName
echo ""
echo ""
cat < /tmp/NewFileName
echo ""
echo ""
mynewfile=""
newline=0
n="1"
read -d '' -r myfile < /tmp/NewFileName
while true
do
	if [ $newline -ge ${#myfile} ]
	then
		break
	fi
	if [ "${myfile:$newline:2}" = "0$n" ]
	then
		mynewfile=$mynewfile${myfile:$newline:1}$'\n'
	else
		mynewfile=$mynewfile${myfile:$newline:1}
	fi
	newline=$[ ( $newline + 1 ) ]
done
echo "$mynewfile" > /tmp/File
cat < /tmp/File

Results:-
Code:
Last login: Fri Feb 28 22:36:40 on ttys000
AMIGA:barrywalker~> ./rm_nl_1.sh
10,"Special Projects,bangaram",0,,0
10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation)",	bangaram,0,,0
10,"Complience with SVCCL",	bangaram,	0,,	0
10,	"Release of incentives / commission to all channel partners.
",	bangaram,	0,,	0
10,"Timely processing of sales orders to channel partners",	bangaram,	0,,	0
10,"	Balance sheet Reviwe", bangaram,	0,,	0
10,"	Ensuring Critical Reconciliation on monthly basis. (IN-GL)",	bangaram,	0,,	0
10,	"Timely & accurate closure of Accounts.
",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram	,0,,	0


10,"Special Projects,bangaram",0,,010,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation)",	bangaram,0,,010,"Complience with SVCCL",	bangaram,	0,,	010,	"Release of incentives / commission to all channel partners.",	bangaram,	0,,	010,"Timely processing of sales orders to channel partners",	bangaram,	0,,010,"	Balance sheet Reviwe", bangaram,	0,,	010,"	Ensuring Critical Reconciliation on monthly basis. (IN-GL)"bangaram,	0,,	010,	"Timely & accurate closure of Accounts.",	bangaram,	0,,	011,"	Opex Spend on communication activites",	bangaram,	0,,	011,"	Opex Spend on communication activites",	bangaram	,0,0

10,"Special Projects,bangaram",0,,0
10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation)",	bangaram,0,,0
10,"Complience with SVCCL",	bangaram,	0,,	0
10,	"Release of incentives / commission to all channel partners.",	bangaram,	0,,	0
10,"Timely processing of sales orders to channel partners",	bangaram,	0,,	0
10,"	Balance sheet Reviwe", bangaram,	0,,	0
10,"	Ensuring Critical Reconciliation on monthly basis. (IN-GL)",	bangaram,	0,,	0
10,	"Timely & accurate closure of Accounts.",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram,	0,,	0
11,"	Opex Spend on communication activites",	bangaram	,0,,	0
AMIGA:barrywalker~> _


Last edited by wisecracker; 02-28-2014 at 06:57 PM..
# 18  
Old 03-02-2014
Hi Wisecracker,
i used this code
Code:
#!/bin/bash
# rm_newline.sh
cat bunny 
tr -d '\n' < bunny > NewFileName
echo ""
echo ""
cat < NewFileName
echo ""
echo ""
mynewfile=""
newline=0
n="1"
read -d  -r bunny < NewFileName
while true
do
	if [ $newline -ge ${#bunny} ]
	then
		break
	fi
	if [ "${bunny:$newline:2}" = "0$n" ]
	then
		mynewfile=$mynewfile${bunny:$newline:1}$'\n'
	else
		mynewfile=$mynewfile${bunny:$newline:1}
	fi
	newline=$[ ( $newline + 1 ) ]
done
echo "$mynewfile" > File
cat < File

but when i run this it shows some errors i.e
Code:
': No such file or directory


rm_newline.sh: line 30: syntax error: unexpected end of file

plz tel me.. here my file name is Bunny..
I beginner to shell script..
i dont have any experience to write script.
# 19  
Old 03-02-2014
Wisecracker used:
Code:
read -d '' -r

instead of
Code:
read -d  -r

# 20  
Old 03-02-2014
SAME ERROR OCCURED NO CHANGE..
# 21  
Old 03-02-2014
("You are trying to run before you can walk.")
I was unsure whether to post this but decided to so in the end...

Look at your error report(s)...

Your code says "bunny", you say it is "Bunny". Which is it?

More to the point WHERE is it?

Either change the full path to point to it directly or ensure it is in the
your current drawer that this code is looking at...
Also ensure you have the needed permissions to access it.

I also quoted the code as being _old_style_ bash scripting so as to hopefully
give you some insight and to search the WWW for what each line might
be doing and for you to greatly improve on it.

Also it will only work for lines 10 - 19, if you want 20 - pseudo_infinity
then have a go at working it out for yourself; it does get difficult but you'll
learn a lot quickly by mistakes and finding out how to correct them.

Yes it can be improved considerably and there are some seriously clever
guys on here capable of doing it...

There are also different methods too but my method was purely to
demonstrate that it can be done the way I originally stated in my pseudo_code
post...

I, (an amateur), and my professional _cousins_ on here, cannot possibly
be a tutorial class. There are many tutorials to be found on the WWW including
this site to help you and the Admin have prepared all the "man" pages too...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX file with Newlines

Hi Friends, I have a data file with new lines. How to remove the newlines and should be showed in one line. I tried using the command tr -d '\n' filename sed 's/\n//g' file name Ex: 1 abc hyd is actual record but in our scenario showing it as 1 abc hydthis record should be like... (5 Replies)
Discussion started by: victory
5 Replies

2. UNIX for Beginners Questions & Answers

Remove newlines and carriage return from a csv file using UNIX

I need to remove new lines and carriage returns from csv file. Is there anything other than sed and gwak by which we could achieve this ? Any suggestions ? (3 Replies)
Discussion started by: A_Gaddale
3 Replies

3. UNIX for Dummies Questions & Answers

Using find with awk to remove newlines

I want to list all html files present in a directory tree, the remove the newline and get one string with a space between files find /home/chrisd/Desktop/seg/geohtml/ -name '*.html' | awk BEGIN{FS=\r} '{print}' ---------- Post updated at 06:47 PM ---------- Previous update was at 06:25 PM... (5 Replies)
Discussion started by: kristinu
5 Replies

4. Shell Programming and Scripting

Need help with eliminating newlines with Perl

Good morning, I need some help with getting rid of newlines with the output from a MYSQL query and putting the information into the right format that I need. Here is the script as it is today: #!/usr/bin/perl my $uda = system("/opt/incontrol/mysql/bin/mysql -u root -ppassword... (2 Replies)
Discussion started by: brianjb
2 Replies

5. Shell Programming and Scripting

removing newlines after a certain word.

Hello! This is my first post here. I have a file with text like: A</title> B C</title> D I need to format it to: AB CD I am trying to use sed: sed 's/<//title>\n/ /g' file > newfile to delete </title> and the newline character, but the file is unchanged because there are... (3 Replies)
Discussion started by: DaytonCPS
3 Replies

6. Shell Programming and Scripting

Delete newlines after every one space

Hi All, I have a file which looks like this: abc 3456 computer 3214 printer 0.9823 computer 3214 Can anyone please let me know how I can format my text like this? abc 3456 computer 3214 printer 0.9823 computer 3214 I know how to space to newlines using tr but don't know how to do... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. Shell Programming and Scripting

sed remove newlines and spaces

Hi all, i am getting count from oracle 11g by spooling it to a file. Now there are some newline characters and blank spaces i need to remove these. pl provide me a awk/sed solution. the spooled file is attached. i tried this.. but not getting req o/p (6 Replies)
Discussion started by: rishav
6 Replies

8. Shell Programming and Scripting

Remove improperly placed newlines

Hello, there. I have a file that's a horrible, horrible mess. (Basically, it's an export from a firewall config.) The people who generated the file didn't think that putting a newline in the middle of a hostname would ever be a problem. It is. Here's an example of the stuff in the file: ... (2 Replies)
Discussion started by: mikesimone
2 Replies

9. Shell Programming and Scripting

Transpose with two newlines as delimiter

Hi Guys, I have data in a file as follows: a 1 2 3 b 4 5 6 a 6 7 8 a 4 7 9 b 6 8 5 c 0 8 7 So the number of rows which have data is variable (2 for the first group, one for the second group and three for the third group), but the delimiters between the... (10 Replies)
Discussion started by: npatwardhan
10 Replies

10. Shell Programming and Scripting

awk - need to remove unwanted newlines on match

Context: I need to remove unwanted newlines from a data file listing books and associated data. Here is a sample listing ( line numbers included ): 1 360762| Skip-beat! 14 /| 9781421517544| nb | 2008.| Nakamura, Yoshiki.| NAKAMUR | Kyoko Mogami followed 2 her true love Sho to Tokyo to... (6 Replies)
Discussion started by: Bubnoff
6 Replies
Login or Register to Ask a Question