target string to delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting target string to delete
# 1  
Old 09-27-2011
target string to delete

Hi all,
I have a text file with a lot of records.
In each records I have tags like this:

Code:
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-C.UNIV\\$bBNCS-C.UNIV\\$h1974-77.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL
=952 \\$aBNCS-CH1989-96,1998-2008.\\$bBNCS-CH1989-96,1998-2008.\\$h\\$oBNCS-CH1989-96,1998-2008.0000001\\$pBNCS-CH1989-96,1998-2008.0000001\\$yJNL

I must format the $a and $b column in order to delete the "-" and text could not be > to 10 caracters.
So here is the exemple as the files have to be at the end:

Code:
=952 \\$aBNCSCH\\$bBNCSCH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCSC.UNIV\\$bBNCSC.UNIV\\$h1974-77.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL
=952 \\$aBNCSCH1989\\$bBNCSCH1989\\$h\\$oBNCS-CH1989-96,1998-2008.0000001\\$pBNCS-CH1989-96,1998-2008.0000001\\$yJNL

As yoou can see, the rest of the column is the same.
How can I do this? If $a and $b were the same in each records I could do that with replace but it's always diferent.

Thanks
# 2  
Old 09-27-2011
Code:
awk -F'\\\\\\\\' '{
  sub(/-/, x, $2)
  sub(/-/, x, $3)
  $2 = substr($2, 1, 12)
  $3 = substr($3, 1, 12)
  }1' OFS='\\\\' infile

# 3  
Old 09-27-2011
Hi
Thanks for your prompt answer.
I think there is a problem,
I paste here one record:
This is the original before the awk command.

Code:
=LDR  00901nas  2200205 i 4500
=005  20061017111721.0
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062
=041  0\$aspa
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.
=260  \\$aMadrid : $bGarsi, $c1972-1998.
=270  \\$aLondres 17. 28028 Madrid
=300  \\$c26 cm.
=310  \\$aBimensual
=525  \\$aTiene como suplemento: "Actas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines. Suplemento", ISSN, 1137-604X.
=650  14$aPsiquiatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1988-1989)1990-91(1992)1993(1994)1995-97(1998).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL

As you see, there are a lot of TAGS starting with =
I only want to apply the awk into the TAG =952
Because after aplying the code look the result:

Code:
=LDR  00901nas  2200205 i 4500\\\\
=005  20061017111721.0\\\\
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062\\\\
=041  0\$aspa\\\\
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines\\\\
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.\\\\
=260  \\$aMadrid : $\\
=270  \\$aLondres 17\\
=300  \\$c26 cm.\\
=310  \\$aBimensual\\
=525  \\$aTiene como\\
=650  14$aPsiquiatr{rcommaa}a.\\\\
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329\\\\
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287\\\\
=952 \\$aBNCSCH\\$bBNCSCH\\$h(1988-1989)1990-91(1992)1993(1994)1995-97(1998).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
\\\\

The =952 is ok, but for exemple you have the =260 truncated...

before:
Code:
=260  \\$aMadrid : $bGarsi, $c1972-1998.

After:
Code:
=260  \\$aMadrid : $\\

Is it possible to apply just into =952?

Thanks
# 4  
Old 09-27-2011
Here's one way to do it with Perl -

Code:
$
$
$ cat f27
=LDR  00901nas  2200205 i 4500
=005  20061017111721.0
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062
=041  0\$aspa
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.
=260  \\$aMadrid : $bGarsi, $c1972-1998.
=270  \\$aLondres 17. 28028 Madrid
=300  \\$c26 cm.
=310  \\$aBimensual
=525  \\$aTiene como suplemento: "Actas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines. Suplemento", ISSN, 1137-604X.
=650  14$aPsiquiatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h(1988-1989)1990-91(1992)1993(1994)1995-97(1998).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-CH\\$bBNCS-CH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCS-C.UNIV\\$bBNCS-C.UNIV\\$h1974-77.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL
=952 \\$aBNCS-CH1989-96,1998-2008.\\$bBNCS-CH1989-96,1998-2008.\\$h\\$oBNCS-CH1989-96,1998-2008.0000001\\$pBNCS-CH1989-96,1998-2008.0000001\\$yJNL
$
$
$
$ perl -lne 'if (/^(=952\s*)(\\\\\$a)(.*?)(\\\\\$b)(.*?)(\\\\.*)$/) {
              ($p, $q, $r, $s, $t, $u) = ($1, $2, $3, $4, $5, $6);
              $r =~ s/-//g; $r =~ s/^(.{10}).*/$1/;
              $t =~ s/-//g; $t =~ s/^(.{10}).*/$1/;
              print "$p$q$r$s$t$u"
            } else {print}
           ' f27
=LDR  00901nas  2200205 i 4500
=005  20061017111721.0
=008  920528d19721998sp\br\p\r\\\\\0\\\a\spa\d
=022  0\$a0300-5062
=041  0\$aspa
=210  0\$aActas Luso Esp Neurol Psiquiatr Cienc Afines
=245  00$aActas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines /$cGrupo para el progreso de la Psiquiatria.
=260  \\$aMadrid : $bGarsi, $c1972-1998.
=270  \\$aLondres 17. 28028 Madrid
=300  \\$c26 cm.
=310  \\$aBimensual
=525  \\$aTiene como suplemento: "Actas Luso Espa{ogon}olas de Neurolog{rcommaa}a, Psiquiatr{rcommaa}a y Ciencias Afines. Suplemento", ISSN, 1137-604X.
=650  14$aPsiquiatr{rcommaa}a.
=780  00$aEs continuaci{dbldotb}n de. $tActas luso-espa{ogon}olas de neurolog{rcommaa}a y psiquiatr{rcommaa}a$xISSN 0001-7329
=785  00$cContinuada por$tActas Espa{ogon}olas de Psiquiatr{rcommaa}a $xISSN 1139-9287
=952 \\$aBNCSCH\\$bBNCSCH\\$h(1988-1989)1990-91(1992)1993(1994)1995-97(1998).\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCSCH\\$bBNCSCH\\$h1989\\$oBNCS-CH0000001\\$pBNCS-CH0000001\\$yJNL
=952 \\$aBNCSC.UNIV\\$bBNCSC.UNIV\\$h1974-77.\\$oBNCS-C.UNIV0000001\\$pBNCS-C.UNIV0000001\\$yJNL
=952 \\$aBNCSCH1989\\$bBNCSCH1989\\$h\\$oBNCS-CH1989-96,1998-2008.0000001\\$pBNCS-CH1989-96,1998-2008.0000001\\$yJNL
$
$
$

tyler_durden

PS: Not sure why that text gets underlined on its own, or how to fix that.
# 5  
Old 09-28-2011
Code:
awk -F'\\\\\\\\' '/^=952/ {
  sub(/-/, x, $2)
  sub(/-/, x, $3)
  $2 = substr($2, 1, 12)
  $3 = substr($3, 1, 12)
  }1' OFS='\\\\' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

3. Shell Programming and Scripting

Need shell script to compare directories and delete files on target server

Hello, I need help in writing the shell script for below mentioned case. There are 2 servers(server A, server B). A cronjob syncs files between these 2 servers. Existing script is copying files from A to B. This is done using the command rsync. However, the files are not deleted... (2 Replies)
Discussion started by: SravaniVedam11
2 Replies

4. HP-UX

Unable to delete iscsi target

Hi Please can someone give me a hint on this, when I list the targets, I see two o them: #iscsiutil -p Operational Target Information ------------------------------ Target # 1 ----------- Target Name : iqn.1992-08.com.netapp:sn.142241859 Target Alias ... (2 Replies)
Discussion started by: fretagi
2 Replies

5. Shell Programming and Scripting

Target string with gsub

Hey guys, I am learning awk and came across gsub and testing the target string to do substitution, what am i missing? Thanks in advance. echo "this is a summer" | awk '{gsub(/er/, "x", "summer"); print}' this is a summer The following works: but i don't understand the why the above... (3 Replies)
Discussion started by: Apollo
3 Replies

6. Shell Programming and Scripting

How to delete more than 7 days file from Target folder?

Hi Team, I have to remove files which are more than 7 days in my target directory. I have this script but using this i faced some problems like, removed library files of unix. for abc in `find /xxx/abc/OutputFiles/xxxx_*.txt -type f -mtime +5|xargs ls 1` do echo "xxx files are:"$abc ... (1 Reply)
Discussion started by: harris
1 Replies

7. UNIX for Dummies Questions & Answers

Delete from target a LUN that is mounted on initiator

hi all, i'm new here and i have a question, i wanted to know, what should happen if i delete a LUN that is already mounted on one of my initiators. thanks! (3 Replies)
Discussion started by: slavash
3 Replies

8. Shell Programming and Scripting

rsync delete specific files - from different target folder

Hi, I need to use rsync to delete multiple files(only specified files not all) using --delete option, these files are located in different target folders. Instead of running rsync command multiple times for each file, can we achieve this with one time execution? your help is much... (0 Replies)
Discussion started by: MVEERA
0 Replies

9. Shell Programming and Scripting

rsync delete single file from the target folder

Hi We want to delete a single file from the destiantion directory using rsync. Is it possible to do this ? or Do we have any alternate approaches in rsync( for ex applying some filters ..etc) For ex: ----------------------------------------------- Source (Folder) ... (3 Replies)
Discussion started by: MVEERA
3 Replies

10. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies
Login or Register to Ask a Question