Sponsored Content
Top Forums Shell Programming and Scripting Help - delete content inside square brackets under conditions Post 302913581 by dperboni on Monday 18th of August 2014 03:23:11 PM
Old 08-18-2014
Linux Help - delete content inside square brackets under conditions

I have the file sed1.txt and I need to strip the brackets ([[*]]) and content inside them only when
I have two or three letters followed by a colon.

for example,it may be any letter, not just abc
[[ab:*]]
[[abc:*]]

Code:
#-- cat sed1.txt
1 [[special:linguagem]] FISICA
2 [[ba:matematica:portugues]]PORTUGUES
3 [[zz:aldkljfdljdf:]] [[xy:klsdfafds99:dlfkljlkfdk]]MATEMATICA
4 [[aa:098sdf90df]][[xy:sdfakjlkfsdj]]INGLES [[agh:dkfjlfdjdf]]
5 [[wordtree:wordtreetree:tree]]QUIMICA
6 ARQUITETURA [[gg:eeoeoeoe:pepepep:eoeeeo]]ROMANA
[[as:dlfksjkldf:slkjlkfdjskldf]]7 ENGENHARIA [[aa:lksdfjlkdjfs]]ELETRICA
8 MECATRONICA [[xas:dkfljldfsaklfds]]FRANCES[[ax:skldfjlkdsf:ljsdlfkjldfs]]
9 [[bb:dsflkjladskffds]]LITERATURA [[xx:dsfaa90ssdf90sdf:ajsdfflasd]]
10[[agroneg:ArrOzFeijao | batata]][[xca:lkdjlkasdf:ldjfalkjfsd:lkdsjlkfjdç]] MEDICINA[[sa:dsflkjkldfs]]
11[[ax:lksdjfkl]] [[ss:dljsaflk]] SED [[sx:sdjflkjfsda]]- AWK
12[[xbc:lkjaflkjfds]] UNIX [[ax:kjdlfjdfskadf]]LINUX[[xu:kldfsjkljdfs]] PERL    [[gg:lksdfjlk:jljsdlkjfds:lkjlkjflds]][[hg:dfjkjfdkjfd]][[xdc:dkdkdkdkdk]][[kd:dflkjdfklkldf:djfjklfdasjfadk:jkafdsjklfdsjkldfas:*/*/*/*/]]

I managed to get this:
Code:
# sed -e 's/\[\[.\{2,3\}:.*[^]].*\]\]//g' sed1.txt 

1 [[special:linguagem]] FISICA
2 PORTUGUES
3 MATEMATICA
4 
5 [[wordtree:wordtreetree:tree]]QUIMICA
6 ARQUITETURA ROMANA
ELETRICA
8 MECATRONICA 
9 
10[[agroneg:ArrOzFeijao | batata]]
11- AWK
12

--------------
#-- sed .... the real result should be:

Code:
1 [[special:linguagem]] FISICA
2 PORTUGUES
3 MATEMATICA
4 INGLES
5 [[wordtree:wordtreetree:tree]]QUIMICA
6 ARQUITETURA ROMANA
7 ENGENHARIA ELETRICA
8 MECATRONICA FRANCES
9 LITERATURA
10[[agroneg:ArrOzFeijao | batata]]MEDICINA
11 SED - AWK
12 UNIX LINUX PERL

--------------------------------------------
What do I have to change in the script ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

square brackets

I would like to substitute a phrase which contains square brackets. change TO how? Thanks (2 Replies)
Discussion started by: gilead29
2 Replies

2. Shell Programming and Scripting

WHy the double square brackets?

One of the senior administrators gave me a shell script to modify and it begins as follows: if ] && ] {more code follows} Why the double square brackets? (10 Replies)
Discussion started by: mojoman
10 Replies

3. Shell Programming and Scripting

Double square brackets question

Hi, I just came across an interesting shell script syntax like the one below: ] && (trap 'rm -rf ${WORK_DIR}/*.$$; echo "\n\nInterrupted !!\n\n"; exit 4' 1 2 3 15) Can someone please explain the code snippet above? The trap command bit is fine but ] && is the hazy part. Generally we use an... (2 Replies)
Discussion started by: King Nothing
2 Replies

4. UNIX for Dummies Questions & Answers

Test command - Two square brackets

Hello, Can someone please explain to me the following line, ] && break I do not understand why two test square brackets are used. Thanks, Shantanu ---------- Post updated at 03:38 PM ---------- Previous update was at 03:35 PM ---------- And, also why there's a $ before (echo $c |... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

5. Shell Programming and Scripting

Replacing text between two square brackets

hi guys, i'm writing a script that looks for a unquie id in a file and replaces a string between two square brackets on the same line as the unquie id: ....... ....... 0001 zz 43242 replace this text] name 0002 sd 65466 UK] country ....... ....... how can i find line with id 0001... (6 Replies)
Discussion started by: zaff
6 Replies

6. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

7. Shell Programming and Scripting

Extract text between two square [..] brackets

Hi All, After searching about this, I could find some solutions but I am not sure why it is not working in my case. I have a text file with contents between two square brackets. The text file looks like this: Use tags when you post any code so others can easily read your code. You can... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

8. Shell Programming and Scripting

Compare the value in between square brackets in file

I wanted to compare the value inside the Squre bracket after Colon ( : ) based on any value(seperated by or operator | ) inside the variable Thread and if match found then wnated to store in output file Input file : 20140320 00:08:43.918 INO 35] - Corporate hub is 20140320 00:08:43.918... (2 Replies)
Discussion started by: nes
2 Replies

9. Shell Programming and Scripting

Problem with occurence of square brackets

Hello all, I have the following problem: $ cat infile this is spam and i need this too this is spam and i need this too $ perl -nwe '$_ =~ /]+ \]+)\]\]*\]? (\+)$/; print "$1 - $2\n";' infile i need this - too i need this - and i need this too I am not sure how many occurences of... (13 Replies)
Discussion started by: zaxxon
13 Replies

10. Shell Programming and Scripting

IF statement with square brackets

Hi All, Hope you all are doing good. Yesterday in my project i came across a scenario which i can not guess why it was working in one region and why it was not in another region. Please find my issue below. I am using AIX version 6.0 of UNIX in my project, in shell scripting i have the... (1 Reply)
Discussion started by: mad man
1 Replies
Locale::Codes::LangFam(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangFam(3pm)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangFam(3pm)
All times are GMT -4. The time now is 12:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy