remove spaces between tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove spaces between tags
# 1  
Old 08-22-2011
remove spaces between tags

I am having the data.txt file as follows.

-------
Code:
<RMService>
	<ResControl>
		<ResultCode>FATAL</ResultCode>
		<ServiceTime>38</ServiceTime>
		<DWLControl>
			<requesterLanguage>100</requesterLanguage>
			<requesterLocale>en</requesterLocale>
			<requesterName>NCO A Batch Load</requesterName>
			<requestID>4</requestID>
		</DWLControl>
	</ResControl>
<RMService>

-------

All the spaces, tabs, new lines has to be removed and all the tags has to be in a single line as follows.

-------
Code:
<RMService><ResControl><ResultCode>FATAL</ResultCode><ServiceTime>38</ServiceTime><DWLControl><requesterLanguage>100</requesterLanguge><requesterLocale>en</requesterLocale><requesterName>NCO A Batch Load</requesterName><requestID>4</requestID></DWLControl></ResControl><RMService>

-------

Please not that the space between "NCO A Batch Load" should not be removed. because it is inside the tag.

Can anyone help me out?

Thanks in advance.


Krishnakanth Manivannan

Last edited by pludi; 08-22-2011 at 08:01 AM..
# 2  
Old 08-22-2011
Quote:
Originally Posted by kmanivan82
Code:
<RMService>
	<ResControl>
		<ResultCode>FATAL</ResultCode>
		<ServiceTime>38</ServiceTime>
		<DWLControl>
			<requesterLanguage>100</requesterLanguage>
			<requesterLocale>en</requesterLocale>
			<requesterName>NCO A Batch Load</requesterName>
			<requestID>4</requestID>
		</DWLControl>
	</ResControl>
<RMService>


All the spaces, tabs, new lines has to be removed and all the tags has to be in a single line as follows.
Code:
awk '{$1=$1;printf $0}' file > new.file

# 3  
Old 08-22-2011
this may not be the best way but it shld work

Code:
for i in `cat input`
        do echo "$i\c" >>output
        done

# 4  
Old 08-22-2011
Code:
echo `cat INPUTFILE` | sed 's/> </></g'

This User Gave Thanks to yazu For This Post:
# 5  
Old 08-22-2011
one more ..
Code:
$ xargs < inputfile | sed 's/> </></g'

# 6  
Old 08-22-2011
Or with Perl:

Code:
$
$
$ cat data.txt
<RMService>
       <ResControl>
               <ResultCode>FATAL</ResultCode>
               <ServiceTime>38</ServiceTime>
               <DWLControl>
                       <requesterLanguage>100</requesterLanguage>
                       <requesterLocale>en</requesterLocale>
                       <requesterName>NCO A Batch Load</requesterName>
                       <requestID>4</requestID>
               </DWLControl>
       </ResControl>
<RMService>
$
$
$ perl -plne 'BEGIN {$/=""} s/>\s*</></g' data.txt
<RMService><ResControl><ResultCode>FATAL</ResultCode><ServiceTime>38</ServiceTime><DWLControl><requesterLanguage>100</requesterLanguage><requesterLocale>en</requesterLocale><requesterName>NCO A Batch Load</requesterName><requestID>4</requestID></DWLControl></ResControl><RMService>
$
$

tyler_durden
# 7  
Old 08-23-2011
Code:
$ sed -e 's/^ .* </</' test | tr -d "\n"
<RMService><ResControl><ResultCode>FATAL</ResultCode><ServiceTime>38</ServiceTime><DWLControl><requesterLanguage>100</requesterLanguage><requesterLocale>en</requesterLocale><requesterName>NCO A Batch Load</requesterName><requestID>4</requestID></DWLControl></ResControl><RMService>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to remove leading spaces

OS : RHEL 6.7 Shell : bash I am trying to remove the leading the spaces in the below file $ cat pattern2.txt hello1 hello2 hello3 hello4 Expected output is shown below. $ cat pattern2.txt hello1 hello2 hello3 hello4 (2 Replies)
Discussion started by: John K
2 Replies

2. UNIX for Dummies Questions & Answers

Remove blank spaces

Dear Masters, I want to remove all lines with blank spaces input file: a|abc|0|1 a|abc|2|3 b||3|5 c|def||7 d|def|0|1 Expected: a|abc|0|1 a|abc|2|3 d|def|0|1 I did this awk -F'|' '!/^$/' input (4 Replies)
Discussion started by: radius
4 Replies

3. Shell Programming and Scripting

Remove spaces from the file

Hi All, The output file contains data as below. "20141023","CUSTOMER" ,"COMPANY" ,"IN0515461" ,"" ,"JOSHUA" There are spaces in between the ending " and ,. The number of spaces is random. How can I remove that from the file so that the final output is:... (4 Replies)
Discussion started by: aarsh.dave
4 Replies

4. Shell Programming and Scripting

How to remove spaces on a line?

Hi, suppose I have the following data: albert music=top40 age=20 bob music=punk rock age=25 candy music=r n b age=22 dave music=mozart or bach only age=30 I want to extract and manipulate the music column but it's got spaces in it. How can I substitute the space with an underscore... (2 Replies)
Discussion started by: almonds
2 Replies

5. Shell Programming and Scripting

remove spaces

Hi folks, I need to remove spaces at the end of each line in a *.txt file. it looks like this word 1 word 2 . . . word n i found some sed commands but any of them didnt work so far thank you for your posts (6 Replies)
Discussion started by: Jimmy7
6 Replies

6. Shell Programming and Scripting

Remove spaces in filenames

Hi, I have files like below, In files coming as spaces. Before transfering those files into ftp server. I want to remove the spaces and then can transfer the files into unix server. e.g: filenames are 1) SHmail _profile001_20120908.txt 2) SHmail_profile001 _20120908.txt 3) sh... (3 Replies)
Discussion started by: kirankumar
3 Replies

7. Shell Programming and Scripting

Remove Spaces

Hi All, I have a comma seperated file. I wanna remove the spaces from column 2. I mean i don't wanna remove the spaces those are presnt in column 1. ex: emp name, emp no, salary abc k, abc 11, 1000 00 bhk s, bhk 22, 2000 00 the output should be: emp name, emp no, salary abc k, abc11,... (4 Replies)
Discussion started by: javeed7
4 Replies

8. Shell Programming and Scripting

Remove spaces before a delimiter

Hi All, I need to modify a script to remove spaces from a csv file. The csv file is delimited by the '~' character and I need to remove the spaces which appear before this character. i.e Sample input: LQ001 SWAT 11767727 ~9104 ~001 ~NIRSWA TEST 18 ~2 ~Standard Test ~0011 Desired... (5 Replies)
Discussion started by: SRyan84
5 Replies

9. UNIX for Dummies Questions & Answers

remove spaces btw

filename contains: 123 4 1234 5 12345 689 i want result: 1234 12345 12345679 cat filename | awk '{print $1, $2, $3}' will get my result, but too many $$s. sed -e 's///g' filename will take care one space, will take 2 spaces. is it a short way to do this ? (7 Replies)
Discussion started by: tjmannonline
7 Replies

10. Shell Programming and Scripting

Remove spaces from columns

I have a file with only one field something like this : 213.45 220.65 240.47 345.67 320.45 I want to remove all spaces in between. Is there any unix command for that ?Thanks in advance.. (2 Replies)
Discussion started by: jacks
2 Replies
Login or Register to Ask a Question