The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ld: fatal: relocations remain against allocatable but non-writable sections tdallagn SUN Solaris 0 05-21-2008 07:58 AM
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 01:12 PM
Delete ^ using sed us_pokiri UNIX for Dummies Questions & Answers 5 04-22-2008 01:20 AM
Can't delete anything in /usr ms1951 UNIX for Dummies Questions & Answers 4 10-22-2004 11:49 AM
delete lesstjm UNIX for Dummies Questions & Answers 3 11-08-2001 03:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-25-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
delete and remain 2 value

Hello Friend,

I have the followint command to delete 4th field and move forward. Can I delete all filed and just remain the first 2?
sed -e "/^[ ]*<Number/s/\([^ ]\) \([^ ]\)/\1\2/g" -e "/^[ ]*<Number/s/\([0-9][0-9][0-9]\)./\1/" -e "/^[ ]*<Number/s/\([0-9][0-9]\)/\1 /g" -e "/^[ ]*<Number/s/0</</" file

input
<Number>00000000<Number>
<Number>0123456<Number>
<Number>4403459411<Number>

output
<Number>00<Number>
<Number>01<Number>
<Number>44<Number>
  #2 (permalink)  
Old 05-25-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
sed -e "s/\(<[^>]*>..\)[^<]*\(<[^>]*>\)/\1\2/g" file
If you believe in 'beauty in brevity'

Code:
sed -e "s/\(>..\)[^<]*/\1/g" file
  #3 (permalink)  
Old 05-25-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by vino
Code:
sed -e "s/\(<[^>]*>..\)[^<]*\(<[^>]*>\)/\1\2/g" file
If you believe in 'beauty in brevity'

Code:
sed -e "s/\(>..\)[^<]*/\1/g" file
thx, but the file have many different fileds should as <customer>, <price>, etc
I ONLY need to do <Number>, how your settlement work for this?
  #4 (permalink)  
Old 05-25-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by happyv
thx, but the file have many different fileds should as <customer>, <price>, etc
I ONLY need to do <Number>, how your settlement work for this?
Then it becomes much simpler

Code:
sed -e "s/\(<Number>..\).*\(<Number>\)/\1\2/g" file
  #5 (permalink)  
Old 05-25-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
Code:
awk '
    { if  (match($0,"<Number>")){
            print substr($0,0,RLENGTH) substr($0,RLENGTH+1,2)"<Number>"           
      }
    }' "file"
  #6 (permalink)  
Old 05-25-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
Thanks all. It work.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0