Help me to find a solution using UNIX commands

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Help me to find a solution using UNIX commands

I have the below requirement. below is the content of the input file and my expected result
Input file: a.txt
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>

Output File:b.txt
<?xml version="1.0" encoding="UTF-8"?><Employee><Name>XXXX</Name><ID>1233</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?><Employee><Name>YYYY</Name><ID>1345</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?><Employee><Name>AAAA</Name><ID>1145</ID></Employee>

I am aware that we can acheive the output by using the below perl command
perl -plne 'BEGIN {$/=""} s/>\s*</></g' a.txt > b.txt

Could some one suggest a way to acheive the same using UNIX commands?

Thanks in Advance

Last edited by Scott; 06-11-2013 at 10:19 AM.. Reason: Use code tags, as stated in the rules and shown IN BIG LETTERS when creating a post.
# 2  
awk '{$1=$1}1' ORS="</ID></Employee>\n" RS="</ID>\n</Employee>" file
<?xml version="1.0" encoding="UTF-8"?> <Employee> <Name>XXXX</Name> <ID>1233</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?> <Employee> <Name>YYYY</Name> <ID>1345</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?> <Employee> <Name>AAAA</Name> <ID>1145</ID></Employee>

Last edited by Franklin52; 06-11-2013 at 10:45 AM.. Reason: Please use code tags
# 3  
Perl is as much of a Unix command today as AWK is. Like Paste.
$ paste -d"\0" - - - - - < file
<?xml version="1.0" encoding="UTF-8"?><Employee> <Name>XXXX</Name> <ID>1233</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?><Employee> <Name>YYYY</Name> <ID>1345</ID></Employee>
<?xml version="1.0" encoding="UTF-8"?><Employee> <Name>AAAA</Name> <ID>1145</ID></Employee>

Last edited by Scott; 06-11-2013 at 12:47 PM.. Reason: Clarified intention of first sentence.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #845
Difficulty: Medium
Sideloading is a term used mostly on the Internet, similar to "upload" and "download", but in reference to the process of transferring files between two local devices, in particular between a computer and a mobile device such as a mobile phone,
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Beginner UNIX question. tail and find commands

hey guys, i'm in a unix course.. and while this is a homework question - i did put alittle effort into it. just wanted to ask before trial and error drives me nuts. question 13 has us saving the last 30 characters of a file into another file and question 14 has us saving the list of all the... (1 Reply)
Discussion started by: labelthief
1 Replies

2. UNIX for Dummies Questions & Answers

Need to modify a delimited file using UNIX commands. Please find description

i have a '|' delimited file having 4 fields. now i want to sort the data by combination of first three fields without changing order of 4th field. input file looks like this: 3245|G|kop|45 1329|A|uty|76 9878|K|wer|12 3245|G|kop|15 1329|A|uty|56 9878|K|wer|2 3245|G|kop|105... (4 Replies)
Discussion started by: ankurgoyal2408
4 Replies

3. Red Hat

alias ip problem,i canīt find out solution

hi, we have eth1; in the beginning it was proposed to create from eth1, eth1.2500 and eth1.240. It did not worked cause vlan 1.2500 was not tagged in the switch. so they decided to leave eth1 like a physical interface with eth1.2500 config (removel vlan tag) and create eth1.240 but it did... (0 Replies)
Discussion started by: pabloli150
0 Replies

4. Programming

Where to find sources of UNIX commands???

Dear friends, I believe that all unix commands are programs which are written in c language, please correct me if I am wrong. Now suppose that I want to see the c source of common commands like echo, ls, mkdir etc, where I can I find the source, linux is open source I believe, so the source for... (2 Replies)
Discussion started by: gabam
2 Replies

5. Shell Programming and Scripting

Please can you help me find a solution in this program in unix ?

Write shell script to read 3 numbers and print them in revers and print wither they are polyndrome numbers or not ????? (2 Replies)
Discussion started by: lovelorn_mn
2 Replies

6. Shell Programming and Scripting

Expect Script - Need help to find solution

I am facing below issue with my script. below is one of the test out of 50 test from the tool which i m trying to automate. the test may show up or may not depending upon the previous results and also from the test some inputs may be asked or may not be asked depending upon previous results so you... (1 Reply)
Discussion started by: snehalb
1 Replies

7. UNIX for Advanced & Expert Users

I need help to find some unix commands

Hey everyone, I need some help for some unix commands. - List all processes in the file "ProcessUser.txt" sorted by the users and in the file "ProcessName.txt" sorted by the name of the process. - How much time does the command "ls -alR /" need and compared to that, how much time is... (2 Replies)
Discussion started by: ZOCKER3000
2 Replies

8. Shell Programming and Scripting

find filenames like unix commands

Hi, I need to write a small script to search in some specific directories to check if any file is present with a unix command name... Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file. Please help Thanks, D (6 Replies)
Discussion started by: deepakgang
6 Replies

9. UNIX for Dummies Questions & Answers

Unix Find commands

thank you for the help (1 Reply)
Discussion started by: scooter17
1 Replies

10. UNIX Desktop Questions & Answers

where i can find list of UNIX commands for daily operations ?

Hi There, Can anyone help, where i can find list of UNIX commands just for regulat day ro day operations Thanx MGR (1 Reply)
Discussion started by: mgoutham
1 Replies

Featured Tech Videos