delete and move number forward..in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete and move number forward..in file
# 1  
Old 02-28-2007
delete and move number forward..in file

I have a file, can I just modify the <number> field and delete the 3rd number and move 4th number to 3rd.. (surely, delete the last digit)?

<john>
<Number>11 20 03 22 23 21 91 00 F0</Number>
<peter>
<Number>12 20 03 20 99 21 91 20 F0</Number>
<ken>
<id>
<Number>10 21 03 21 78 21 92 27 F0</Number>

output like
<john>
<Number>11 00 32 22 32 19 10 0F</Number>
<peter>
<Number>12 00 32 09 92 19 12 0F</Number>
<ken>
<id>
<Number>10 10 32 17 82 19 22 7F</Number>

Thank's all!!

Last edited by happyv; 02-28-2007 at 03:24 AM..
# 2  
Old 02-28-2007
Code:
sed "/^<Number>/{s/<Number>\(.*\)<\/Number>/\1/;s/ //g;s/.//3;s/../& /g;s/ .$//;s/.*/<Number>&<\/Number>/;}" file

# 3  
Old 02-28-2007
Anbu..

You are too good!!!
# 4  
Old 02-28-2007
Quote:
Originally Posted by anbu23
Code:
sed "/^<Number>/{s/<Number>\(.*\)<\/Number>/\1/;s/ //g;s/.//3;s/../& /g;s/ .$//;s/.*/<Number>&<\/Number>/;}" file

the command failed..
sed: command garbled
# 5  
Old 02-28-2007
Its working for me. Try copy the command and execute as such.
# 6  
Old 02-28-2007
see if this is what you want:
Code:
sed 's/\(Number> [0-9]* [0-9]*\) [0-9]*/\1/' filename

# 7  
Old 02-28-2007
Quote:
Originally Posted by Yogesh Sawant
see if this is what you want:
Code:
sed 's/\(Number> [0-9]* [0-9]*\) [0-9]*/\1/' filename

but i also need to delete the last digit...as well
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Move directory with rsync and delete from source

I need a rsync command which will exclude certain files and directories from source and copy the rest. I got this command working, sudo rsync -avzh --exclude 'bin' --exclude 'braintree' --exclude 'colinmollenhour' --exclude 'composer' --exclude 'doctrine' --exclude 'fabpot' --exclude... (2 Replies)
Discussion started by: Siddheshk
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Delete or move post to applescript area

i posted an applescript question in the wrong area, trying frantically to delete or move before I get in trouble for posting question in wrong area. it is the one about opening webpages and searching text with applescript, thanks (1 Reply)
Discussion started by: ilovedoritos
1 Replies

3. Shell Programming and Scripting

Move and later delete mail data of nonexistant users.

Hello everyone! i hope u can help me... i need a script that is able to do: When a user gets deleted in the ldap DB, the mail folder remains. How can i move to another location and delete it after a month? :wall: (2 Replies)
Discussion started by: newbreaker12
2 Replies

4. Ubuntu

Iptables forward traffic to forward chain!!!

Hi, I am new to linux stuff. I want to use linux iptables to configure rule so that all my incoming traffic with protocol "tcp" is forwarded to the "FORWARD CHAIN". The traffic i am dealing with has destination addresss of my machine but i want to block it from coming to input chain and somehow... (0 Replies)
Discussion started by: arsipk
0 Replies

5. UNIX for Dummies Questions & Answers

Delete large number of columns rom file

Hi, I have a data file that contains 61 columns. I want to delete all the columns except columns, 3,6 and 8. The columns are tab de-limited. How would I achieve this on the terminal? Thanks (2 Replies)
Discussion started by: lost.identity
2 Replies

6. Shell Programming and Scripting

How to delete several lines from file by line number?

Hi I am using the following command to delete a line from the file by line number: line_number=14 sed "${line_number}d" inputfilename > newfilename Is there a way to modify this command to specify the range of lines to be deleted, lets say from line 14 till line 5 ? I tried using the... (5 Replies)
Discussion started by: aoussenko
5 Replies

7. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

move contents from one file to another based on line number or content

I want a script that will move everything beyond a certain line number or beyond a certain content word into another file. For example, if file A has this: first line second line third line forth line fifth line sixth line I want to run a script that will move everything beyond the third... (4 Replies)
Discussion started by: robp2175
4 Replies

9. Shell Programming and Scripting

Bash rsync but move not delete

There might be an easy solution to my problem, or maybe not, but here it is. I am trying to rsync a Volume with 1.5 terabytes of data and send it via fibre channel to a raid array. Now normally when I rsync it scans through everything and, before copying anything, deletes any files that have... (1 Reply)
Discussion started by: Movomito
1 Replies

10. UNIX for Dummies Questions & Answers

Script to move certain number of files every 10 minutes.

Hi, I need to move a certain number of files every 10 minutes from one folder to another. I have written the script below, however its not working, please advise. #! /bin/ksh start() { mv /test1/$(head -1000 /movetst) /test2/ sleep 600 } stop() { exit } ls ti* >... (1 Reply)
Discussion started by: amitsayshii
1 Replies
Login or Register to Ask a Question