copying to the end of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying to the end of the line
# 1  
Old 09-19-2011
copying to the end of the line

Hi,
I have a file as such

1 <text1><text2></
2 <text3><text4></
3 <text5><text6></
4 <text7><text8></

I need is so the first bit of text in the line is at the end as its xml so

1 <text1><text2></text1>
2 <text3><text4></text3>
3 <text5><text6></text5>
4 <text7><text8></text7>

Anyone know a way I can do this?

Thanks for any help you can give
# 2  
Old 09-19-2011
Like this?

Code:
echo '<text1><text2></' | awk -F '<' '{print $0$2}'

This User Gave Thanks to clx For This Post:
# 3  
Old 09-19-2011
Input:
Code:
$ cat file
1 <text1><text2></
2 <text3><text4></
3 <text5><text6></
4 <text7><text8></

Output:
Code:
$  awk -F '[<.*>]' '{print $0 $2">"}' file
1 <text1><text2></text1>
2 <text3><text4></text3>
3 <text5><text6></text5>
4 <text7><text8></text7>

Guru
This User Gave Thanks to guruprasadpr For This Post:
# 4  
Old 09-19-2011
thanks alot the awk one worked a dream Smilie

great work
Smilie
# 5  
Old 09-19-2011
Through Sed..
Code:
sed 's/\([a-z][a-z0-9]*>\).*/&\1/' inputfile

# 6  
Old 09-19-2011
One more question i promise Smilie

I have this

<A="B/C/D"/><E="F" G="H"><![I]]></

and i need to get rid of the last bit <![I]]></ and also move the / from the end of the first <> to the end of the second.

<A="B/C/D"><E="F" G="H"/>

Any help would be much apprenciated Smilie
# 7  
Old 09-19-2011
Code:
echo '<A="B/C/D"/><E="F" G="H"><![I]]></' | sed -e 's#><!\[I]]>.*$#/>#g' -e 's#/>#>#1'
<A="B/C/D"><E="F" G="H"/>

--ahamed

Last edited by ahamed101; 09-19-2011 at 10:55 AM.. Reason: thanks ctsgnb, modified the code to escape only opening braces!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

3. Shell Programming and Scripting

How to set end limit while copying files of a range??

I have files being generated in format A20140326.00........ to A20140326.24............. I need to copy these hourly basis from one location to another. Eg. If i copy from 14 to 19 the hour, I use wildcard as A201403226.1*. Requirement is : I need to copy from 06 hour and wil run the script... (1 Reply)
Discussion started by: Saidul
1 Replies

4. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

5. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

6. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

7. Programming

concatinate all lines from second line to end of line in perl

I have datafile like ~dta.yunm shhshsgggssssjsksjs sggsjshsjsjssss shshshhshshshs i wish to take only first line and all other lines in concatenated form in second line what should I do??? output like ~dta.yunm shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs please tell me how... (7 Replies)
Discussion started by: sujit_singh
7 Replies

8. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

9. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

10. Shell Programming and Scripting

copying from line N1 to line N2 of a file in a series of files

Dear community, I'm quite a newbie with scripting, I have this problem: I have a file with many lines and I want to copy the lines from 1 to N to file.1, from N+1 to 2N to file.2, and so on up to the end of the file I have tried with something like this (N=43 in this example): awk '{for... (2 Replies)
Discussion started by: paolalup
2 Replies
Login or Register to Ask a Question