AWK script issue for the part regular expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK script issue for the part regular expression
# 1  
Old 11-23-2010
Network AWK script issue for the part regular expression

Hi I am having a file as shown below

FILE 1
Code:
TXDD00, TXDD01, TXDD02, TXDD03,
        TXDD04, TXDD05, TXDD06, TXDD07,
        TXDD08, TXDD09, TXDD10, TXDD11,
        TXDD12, TXDD13, TXDD14, TXDD15,
        TXDD16, TXDD17, TXDD18, TXDD19,
        TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1, TXDJTAGOE,
        TXDOE, TXEBSIN, TXED00, TXED01,
        TXED02, TXED03, TXED04, TXED05,
        TXED06, TXED07, TXED08, TXED09,
        TXED10, TXED11, TXED12, TXED13,
        TXED14, TXED15, TXED16, TXED17,
        TXED18, TXED19, TXEDCLK, TXEJTAGAMPL0,
        TXEJTAGAMPL1, TXEJTAGOE, TXEOE, TXFBSIN,
        TXFD00, TXFD01, TXFD02, TXFD03,
        TXFD04, TXFD05, TXFD06, TXFD07,
        TXFD08, TXFD09, TXFD10, TXFD11,
        TXFD12, TXFD13, TXFD14, TXFD15,
        TXFD16, TXFD17, TXFD18, TXFD19,
        TXFDCLK, TXFJTAGAMPL0, TXFJTAGAMPL1, TXFJTAGOE,
        TXFOE, TXGBSIN, TXGD00, TXGD01,
        TXGD02, TXGD03, TXGD04, TXGD05,
        TXGD06, TXGD07, TXGD08, TXGD09,
        TXGD10, TXGD11, TXGD12, TXGD13,
        TXGD14, TXGD15, TXGD16, TXGD17,
        TXGD18, TXGD19, TXGDCLK, TXGJTAGAMPL0,
        TXGJTAGAMPL1, TXGJTAGOE, TXGOE, TXHBSIN,
        TXHD00, TXHD01, TXHD02, TXHD03,

I need to delete the lines or the words carrying regular expression TXE , TXF , TXG and TXH

I am using below AWK script to delete the lines
Code:
awk '{for(i=1;i<=NF;i++) if ($i~/TXE/){ gsub(/TXE/," ",$i)} }1' FILE1 > HS.TEMP2

but it is not deleting the whole word matching the expression TXE for example TXEBSIN pin is becoming BSIN , it should delete the whole word matching the regular expression , how to do that ?

Thanks and Regards
Jaita

Moderator's Comments:
Mod Comment You already got 2 reminder/infractions for not using code tags. Here is your 3rd - you also got a PM with a guide how and when to use them. If you collect 30 infraction points, you will be automatically banned. Maybe consider this and follow the instructions in the PM for future posts. If something is still not clear, don't hesitate to ask.

Last edited by zaxxon; 11-23-2010 at 07:42 AM..
# 2  
Old 11-23-2010
The regular expression in your substitution is just to replace the 3 characters:
Code:
gsub(/TXE/," "

It should be something like
Code:
gsub(/TXE[^,]/,""

An iteration through all fields should not be necessary.

If I got it right, you want to remove the words, not really the whole line(?), if they are mixed with strings that should be printed. An alternative:

Code:
sed -e 's/TX[EFGH][^,]*,//g' -e '/^[ \t]*$/d' file
TXDD00, TXDD01, TXDD02, TXDD03,
        TXDD04, TXDD05, TXDD06, TXDD07,
        TXDD08, TXDD09, TXDD10, TXDD11,
        TXDD12, TXDD13, TXDD14, TXDD15,
        TXDD16, TXDD17, TXDD18, TXDD19,
        TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1, TXDJTAGOE,
        TXDOE,


Last edited by zaxxon; 11-23-2010 at 10:01 AM.. Reason: typo
# 3  
Old 11-23-2010
Code:
awk '!/TX[EFGH]/' file

# 4  
Old 11-23-2010
Code:
grep -v TX[EFGH] infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

awk regular expression

Hello, I have big files which I wanna filter them based on first column. first column should be one of these strings: chr2L || chr2R || chr3L || chr3R || chr4 || chrX and something like chr2Lh or chrY or chrM3L is not accepted. I used the following command: awk '{ if ($1=="chr2L" ||... (5 Replies)
Discussion started by: @man
5 Replies

3. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

4. Shell Programming and Scripting

perl regular expression not inbetween issue

Dear All, perl -e 'if($ARGV =~ /\A^{10}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '1234567899' Valid string perl -e 'if($ARGV =~ /\A^{8}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '12345678' Valid string individually both works, anyway to combine both... (3 Replies)
Discussion started by: jimmy_y
3 Replies

5. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

6. Shell Programming and Scripting

Grep regular expression to get part of a line

Hi I just started on GNU Grep with regex and am finding it very challenging and need to ask for help already... here is the problem, I have a page (MYFILE) which consists of the following.... <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden"... (2 Replies)
Discussion started by: noobie74645
2 Replies

7. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

8. Shell Programming and Scripting

Regular expression in AWK

Hello world, I was wondering if there is a nicer way to write the following code (in AWK): awk ' FNR==NR&&$1~/^m$/{tok1=1} FNR==NR&&$1~/^m10$/{tok1=1} ' my_file In fact, it looks for m2, m4, m6, m8 and m10 and then return a positive flag. The problem is how to define 10 thanks... (3 Replies)
Discussion started by: jolecanard
3 Replies

9. Shell Programming and Scripting

Regular expression issue

Hi, I have the following string: $string= BG_1_12345_?_XX.SVF The '?' means that any character could be in that position. If from a file i will read the string $str=12345 how can i modify the $str in order to be $str=$string. Best regards, Christos (4 Replies)
Discussion started by: chriss_58
4 Replies

10. UNIX for Dummies Questions & Answers

regular expression and awk

I can print a line with an expression using this: awk '/regex/' I can print the line immediately before an expression using this: awk '/regex/{print x};{x=$0}' How do I print the line immediately before and then the line with the expression? (2 Replies)
Discussion started by: nickg
2 Replies
Login or Register to Ask a Question