delete and remain 2 value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete and remain 2 value
# 1  
Old 05-25-2007
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  
Old 05-25-2007
Code:
sed -e "s/\(<[^>]*>..\)[^<]*\(<[^>]*>\)/\1\2/g" file

If you believe in 'beauty in brevity'

Code:
sed -e "s/\(>..\)[^<]*/\1/g" file

# 3  
Old 05-25-2007
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  
Old 05-25-2007
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  
Old 05-25-2007
Code:
awk '
    { if  (match($0,"<Number>")){
            print substr($0,0,RLENGTH) substr($0,RLENGTH+1,2)"<Number>"           
      }
    }' "file"

# 6  
Old 05-25-2007
Thanks all. It work.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Rsync with --delete but do not delete peer dirs on target

rsync with --delete won't honor the delete if the source is something/*. I want the delete to work, but not to delete directories on the target that are peer to the intended directory. For example, using these source and target file structures: Source on desktop: ~/ Money/ ... (4 Replies)
Discussion started by: JavaMeister
4 Replies

2. Programming

Mismatched free() / delete / delete [] line no missing

Could you tell me the possibilities of the reason to get the Mismatched free() / delete / delete . I unable to see the line no in the valgrind report. it displays the function name. with that function name, I am not able to find where exactly the issue is there.I am getting the Mismatched free()... (3 Replies)
Discussion started by: SA_Palani
3 Replies

3. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

4. Shell Programming and Scripting

Search for duplicates and delete but remain the first one based on a specific pattern

Hi all, I have been trying to delete duplicates based on a certain pattern but failed to make it works. There are more than 1 pattern which are duplicated but i just want to remove 1 pattern only and remain the rest. I cannot use awk '!x++' inputfile.txt or sed '/pattern/d' or use uniq and sort... (7 Replies)
Discussion started by: redse171
7 Replies

5. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

6. UNIX for Dummies Questions & Answers

lpstat print queue remain SENDING status

Hi All, When I type the following command: lpstat -pthcgl240 I get the following : Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- --------- --- ------------------ ---------- ---- -- ----- --- --- thcgl24 @CGBP SENDING 636... (0 Replies)
Discussion started by: nj1986
0 Replies

7. Solaris

ld: fatal: relocations remain against allocatable but non-writable sections

Hello everybody. I've got a problem installing libssh2-0.18 Configure is done without any errors : ./configure --prefix=/home/tdallagn/modap/libssh2 --with-openssl=/home/tdallagn/modap/openssl But the "make" command fails : ld: fatal: relocations remain against allocatable but... (0 Replies)
Discussion started by: tdallagn
0 Replies
Login or Register to Ask a Question