sed to remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to remove
# 15  
Old 05-17-2010
Yes, but then you would have to test for space or tab again:
Code:
sed '/^[0-9]\{9\}[\t ]650/s/[034]$//'

# 16  
Old 05-17-2010
I guess there are many LDR && BK sessions, try to use this rule in code:

Code:
awk '$2=="LDR" {a=1} ($2=="650" && a=1) {sub(/[034]$/,"")} $4=="BK" {a=0}1 ' urfile

# 17  
Old 05-18-2010
Hi
Very good
Thanks a lot, this time I have the solution !!
Great

Cheers

---------- Post updated at 05:17 AM ---------- Previous update was at 12:04 AM ----------

Hello again,

an other question about this file,
In some case I have this:

Code:
000000008 650   L $$aGeneral y miscelánea;4001
000000008 650   L $$aGeneral and miscellaneus;4001

Is it possible to rename the last number with a string? the objective is to get this:

Code:
000000008 650   L $$aGeneral y miscelánea;Quimica
000000008 650   L $$aGeneral and miscellaneus;Chemistery

THanks if you have any idea.
Cheers
# 18  
Old 05-18-2010
I am not sure how to distinguish between the first and second line in your example - they differ only in the content of the penultimate field ("General y miscelánea" vs. "General and miscellaneus").

Based on scrutinizers solution and assuming these two are just two examples and you do not have to differentiate:

Code:
sed '/^[0-9]\{9\}[\t ]650/s/;[0-9]*$/;Quimica/'

This will change the "4001" in your example to "Quimica" in all lines having "650" in the second field.

I hope this helps.

bakunin
# 19  
Old 05-18-2010
Hi

The only diferrence between both records is one is in spanish and the second is in english.
This is a library catalogue with references to BOOKS, so some books exists in several languages.

So if we take my exemple:

Code:
000000008 650   L $$aGeneral y miscelánea;4001
000000008 650   L $$aGeneral and miscellaneus;4001

Am other exemple (other record)

Code:
000000038 650   L $$aQuÃ*mica1; 4007
000000038 650   L $$aChemistry1; 4007

So I need to replace all the code after the ;
I have the correspondance for all the codes.

---------- Post updated at 06:29 AM ---------- Previous update was at 06:14 AM ----------

Hi
sorry
to be more clear, maybe I should explain the issue from the begining... Smilie

The file is a list of bib records like this:

Code:
000000001 LDR   L ^^^^^nam^^2200325Iia^45e0
000000001 022   L $$a0081-3397
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 650   L $$a59000;4001
000000001 FMT   L BK

As you see, LDR and FMT are the start and end of each record.
AS you see, there is a field 650 with some values.
So the objective is to replace the value in each record...by its correspondence (a string as Quimica....etc) in spanish and english.
Some of this records have fields 650 with only one value, but others have 2 values.

The results for the exemple will be:

Code:
000000001 LDR   L ^^^^^nam^^2200325Iia^45e0
000000001 022   L $$a0081-3397
000000001 041   L $$aspa
000000001 088   L $$aJ.E.N. 551
000000001 090   L $$aINFORMES JEN
000000001 650   L $$aFraseUno;FraseDos
000000001 650   L $$aStringOne;StringTwo
 000000001 FMT   L BK

This code is ok if you have only one value:

Code:
 sed -i '/[0-9]\{9\} 650   L $$a55[0-9]\{4\}/{G;s/^\(.* $$a\)[0-9]\{5\}\(.*\)\(\n\)$/\1Ciencias biomédicas, Estudios básicos\2\3\1Biomedical sciences, Basic studies\2/g}' file.dat

But if I have 2 values...it do not works.
Thanks in advance
# 20  
Old 05-18-2010
Understood. I noticed the difference, but wasn't sure if this constitutes the distinctive criterion. In your case, i presume, there is nothing left than to ad-hoc-replace the lines parts:

Code:
sed '/^[0-9]\{9\}[\t ]650/ {
                   s/\(General y miscelánea;\)[0-9]*$/\1Quimica/'
                   s/\(General and miscellaneus;\)[0-9]*$/\1Chemistry/'
                   s/\(QuÃ\*mica1;\)[0-9]*$/\1<whatever-your-replacement-is>/'
                   ...
                   }' /path/to/file > /path/to/outputfile

Some caveats: probably the asterisk in "QuÃ\*mica1" is from differing code pages used, but generally speaking, there are some characters which have a special meaning to sed (asterisk is among them). If you want to match for such a character you will have to precede it with a backslash as escape character. To match an asterisk you will have to search for "\*", not "*", like i did above.

In your second example you have whitespace between the last semicolon and the number following it ("; 4007" instead of ";4007"). If this isn't a typo you will have to change all the matching patterns like this. Notice the added space in the character range definition ("[ 0-9]" instead of "[0-9]"):

Code:
s/\(General and miscellaneus;\)[ 0-9]*$/\1Chemistry/'

I hope this helps.

bakunin
# 21  
Old 05-19-2010
Hi
ok so imagine I have a big list of correspondences, in my exemple it was:
000000001 650 L $$a59000;4001

But there is a lot of code more...
000000001 650 L $$a01000;30000
etc

In reality, only the 2 first number are relevant.Look this list:
01 => stringOne/filaUno
02 => stringTwo/filaDos
30 => ...
40 => ...
So if I have 59000 in the field 650, I must take the corresponance of 59

So in the sed commande I must tell that depending of the 2 first number it's a correspondence or an other...

---------- Post updated at 06:45 AM ---------- Previous update was at 06:44 AM ----------

Hi
and the * is a copy paste issue I think because the real world is:
Química

QuÃ\*mica1

---------- Post updated 05-19-10 at 05:27 AM ---------- Previous update was 05-18-10 at 06:45 AM ----------

Hello
forget the last post, I resolve this by other way.
Now I just need to remove lines like this:

Code:
000000283 008   L 100211s9999\\\\xx\\\\\\\\\\\000\0\spa\d
000000284 008   L 100211s9999\\\\xx\\\\\\m\\\\\000\0\spa\d
000000285 008   L 100211s9999\\\\xx\\\\\\\\\\\000\0\eng\d
000000286 008   L 100211s9999\\\\xx\\\\\\m\\\\\000\0\fre\d

The common point is this:
Code:
'/[0-9]\{9\} 008   L'

The rest can be different
Is there any way to tell SED to remove all the line starting as this pattern?

THanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove space with sed

Hello Folks , myfile contains 1000000 records as follows: logver=56 idseq=63256 itime=1111 devid=TG-40 devname=PUI-C2 vd=USER date=2019_01_10 time=18:39:49 logid="000013" type="traffic" subtype="forward" level="notice" eventtime=134 srcip=1.1.1.1 srcport=1 srcintf="XYX-CORE.01"... (3 Replies)
Discussion started by: arm
3 Replies

2. Shell Programming and Scripting

sed remove everything between two string

Hi all, I have this input: "203324780",,"89321213261247090146","VfdsD150","0D","fd3221","V0343","aaa","Direkt","fsa","2015.02.27","39833,54454,21214",,,"fd","NORMAL","D","10fd","1243 Flotta","HiĂĄnytalan","2013.02.25",,"2013.02.25","2013.02.24","2013.02.28",,"SajĂĄt... (4 Replies)
Discussion started by: snayper
4 Replies

3. UNIX for Dummies Questions & Answers

How to remove certain lines using sed?

Hi I have the following kind of line sin my file . print ' this is first'. print ' this is firs and next ' ' line continuous '. -- this is entire print line. print ' this is first and next ' ' line continuous and' 'still there now over'. -- this 3lines together a single print line. ... (5 Replies)
Discussion started by: Sivajee
5 Replies

4. Shell Programming and Scripting

Need to remove a character using sed

Hi All, I have output like this below ldprod/03 ldprod/02 ldprod/01 ldprod/00 ldnprod/ ldnprod/030 I want only remove all character including / ldprod ldprod ldprod ldprod ldprod ldnprod (8 Replies)
Discussion started by: ranjancom2000
8 Replies

5. Shell Programming and Scripting

Remove the Characters '[' and ']' with Sed

Hi, I am new to Sed and would like to know if it is possible to remove the characters . I have a couple of files with a keyword and would like to remove the substring. I am Using sed s/// but Its not working Thanks for your Support Andrew Borg (2 Replies)
Discussion started by: andrewborg
2 Replies

6. Shell Programming and Scripting

using sed to remove lines

Can somebody explain why my sed command is not working. I do the folloinwg: Generates a binary file to /tmp/x1.out /usr/lib/sa/sa2 -s 4:00 -e 8:00 -i 3600 -A -o /tmp/x1.out decodes the file (no problem so far) sar -f /tmp/x1.out When I do this it does not appear to delete the... (4 Replies)
Discussion started by: BeefStu
4 Replies

7. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

8. Shell Programming and Scripting

sed to remove character ['

I have a huge file where the each column has data in the format: . I want to remove the from each value. How do I do it with sed? thanks (2 Replies)
Discussion started by: manishabh
2 Replies

9. Shell Programming and Scripting

sed remove

anyone out there knows how to remove pattern <random string> use sed? (6 Replies)
Discussion started by: jamwong
6 Replies

10. Shell Programming and Scripting

how to remove ^@ from a file using sed...or anything

i tried the following:- sed -e file 's/^@//g' > temp also tried sed -e file 's///g' > temp nothing happened....can someone please tell me wht is wrong??? also someinformation abt the character "^@"(it is ONLY ONE character and NOT TWO characters) thanx in advance.. (13 Replies)
Discussion started by: sayonm
13 Replies
Login or Register to Ask a Question