awk script problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script problem
# 1  
Old 02-08-2011
awk script problem

Hi
I am having a big file where the interested section is shown below
I need to write one awk script to search for the _N thing and delete it till the blank space
means _N1 or _N4 everything needs to be deleted
Removing the links like _N402 and like that


Code:
 
####################################  
  DPIN DDR3P2DP18A_JTAGBSDDODP10_DP18N0_N402 O
  DPIN DDR3P2DP18A_JTAGBSDDODP11_DP18N0_N403 O
  DPIN DDR3P2DP18A_JTAGBSDDODP12_DP18N0_N404 O
  DPIN DDR3P2DP18A_JTAGBSDDODP13_DP18N0_N405 O
  DPIN DDR3P2DP18A_JTAGBSDDODP14_DP18N0_N406 O
  DPIN DDR3P2AD32SA_JTAGBSDDOADRB03_ADR320_N407 O
  DPIN DDR3P2DP18A_JTAGBSDDODP15_DP18N0_N408 O
  DPIN DDR3P2DP18A_JTAGBSDDODP16_DP18N0_N409 O
  DPIN DDR3P2DP18A_JTAGBSDDODP17_DP18N0_N410 O
  DPIN DDR3P2DP18A_JTAGBSDDODP18_DP18N0_N411 O
  DPIN DDR3P2DP18A_JTAGBSDDODP19_DP18N0_N412 O
  DPIN DDR3P2DP18A_JTAGBSDDODP20_DP18N0_N413 O
  DPIN DDR3P2DP18A_JTAGBSDDODP21_DP18N0_N414 O
  DPIN DDR3P2DP18A_JTAGBSDDODP22_DP18N0_N415 O
  DPIN DDR3P2DP18A_JTAGBSDDODP23_DP18N0_N416 O
  DPIN DDR3P2AD32SA_JTAGBSDDOADRB04_ADR320_N417 O
  DPIN DDR3P2AD32SA_JTAGBSDDOADRB05_ADR320_N418 O
  DPIN DDR3P2AD32SA_JTAGBSDDOADRB06_ADR320_N419 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP00_DP18N0_N420 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP01_DP18N0_N421 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP02_DP18N0_N422 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP03_DP18N0_N423 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP04_DP18N0_N424 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP05_DP18N0_N425 O
  DPIN DDR3P2DP18A_JTAGBSEDIFROMCOREDP06_DP18N0_N426 O
  DPIN DDR3P2AD32SA_JTAGBSDDOADRB07_ADR320_N427 O

Output should be like this
Code:
 
#######################################
DPIN DDR3P2AD32SA_JTAGBSDDOADRB09_ADR320 O
DPIN DDR3P2DP18A_JTAGBSEDODP03_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP04_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP05_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP06_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP07_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP08_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP09_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP10_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP11_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP12_DP18N0 O
DPIN DDR3P2AD32SA_JTAGBSDDOADRB10_ADR320 O
DPIN DDR3P2DP18A_JTAGBSEDODP13_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP14_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP15_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP16_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP17_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP18_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP19_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP20_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP21_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSEDODP22_DP18N0 O
DPIN DDR3P2AD32SA_JTAGBSDDOADRB11_ADR320 O
DPIN DDR3P2DP18A_JTAGBSEDODP23_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSRDODP00_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSRDODP01_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSRDODP02_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSRDODP03_DP18N0 O
DPIN DDR3P2DP18A_JTAGBSRDODP04_DP18N0 O
#############################

My Script Not working : Not giving results

Code:
 
awk '/_N/ {gsub(/_N[0-9]/,"")};1' FILE1 > FILE2

Thanks
Jaita
# 2  
Old 02-08-2011
Quote:
Originally Posted by jaita
#############################
[/CODE]My Script Not working : Not giving results

Code:
 
awk '/_N/ {gsub(/_N[0-9]/,"")};1' FILE1 > FILE2

Thanks
Jaita
The above expression matches only _N1 or _N2 i.e any one number following _N. Add a + to solve this problem.
Code:
awk '/_N/ {gsub(/_N[0-9]+/,"")}1

Unless you have lines other than _N in your file you do not want to search for pattern /_N/ first and then substitute. Directly you can substitute null..as..
Code:
awk 'gsub(/_N[0-9]+/,"")' FILE1 > FILE2

# 3  
Old 02-08-2011
Try this,
Code:
awk -F"[_ ]" '/_N4/{gsub("_"$(NF-1),"",$0)}1'  inputfile

# 4  
Old 02-08-2011
Code:
sed 's/_N[0-9]\{3\}//' infile

# 5  
Old 02-08-2011
Code:
sed 's/_N[14][0-9]*//' infile

# 6  
Old 02-08-2011
Code:
awk '1' RS="_N..."  ORS=  file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script problem

Hello guys i have following problem. I'm trying to copy content of one file and paste this content in all .txt files in directory, but at line 15. My script copy the content at first line, not 15. I'm confused how to do this. Thank you in advance for your help! This is my script: ARGS=2 ... (9 Replies)
Discussion started by: r00ty
9 Replies

2. Shell Programming and Scripting

Awk Script Problem

Can someone please explain to me what is wrong with this awk script? echo 74 85 | awk '{ if ( $1 > $2 ) PRESULTS = ( $1 - $2 ); print $0,"=>","P"PRESULTS ; else if ( $1 > $2 ) NRESULTS = ( $2 - $1... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

problem with awk script

Hi, I have two files Hi, I have two files file1 :> Code: val="10" port="localhost:8080"httpadd="http:\\192.168.0.239" file2 :> Code: val=${val} val="pdssx" port=${port}port="1324"httpadd=${httpadd}httpadd="raamraav"fileloc=${fileloc} file3(or file2) should have following... (1 Reply)
Discussion started by: nitin.pathak
1 Replies

4. Shell Programming and Scripting

Awk script Problem

Hi , I am having two files FILE1 and FILE2 as shown below I need to search each and every element of Coulumn1 in the FILE1 in FILE2 and Globally replace with the Corresponding element of the Column2 in the FILE2 , For example and1 which is the first element of COl 1 of the FILE1 should be... (4 Replies)
Discussion started by: jaita
4 Replies

5. Shell Programming and Scripting

Problem with awk script

Hi, I have one csv file with 3 fileds like tmp1.csv 2079|2010Aug|cardilogy 2349|2010Aug|numerology 2213|2010Aug|immunlogy another csv file with code for those specialities spec.csv cardiology|CRD numerology|NMY immunology|IMY i want to replace the contents of file 1 with codes... (2 Replies)
Discussion started by: Man83Nagesh
2 Replies

6. Shell Programming and Scripting

Problem with an awk Script

hello, first, yes i searched the forum , google and read many tutorials but still have a problem with my script. I have great Problems, because i haven't worked with regular expressions before and never had anything to do with shellscripts. i am a complete Newby in this sort of theme. I have... (8 Replies)
Discussion started by: Crashvogel
8 Replies

7. Shell Programming and Scripting

awk script problem

Hi All, I have the following input data: That I'd like to look like this ($2 is the column I'd like it to appear in) where the entries are grouped by date: The code I have at present is: awk 'BEGIN {} { dt = $1 if (dt == dt_prev) { pp = $3 ... (7 Replies)
Discussion started by: pondlife
7 Replies

8. Shell Programming and Scripting

Problem with a AWK Script

Hi I am having some contents in my file like this file1 ########################## pin (PIN1) { direction : input ; capacitance : 121 ; max_transition : 231 ; } pin (PIN2) { direction : input ; capacitance : 124 ; max_transition : 421 ;... (8 Replies)
Discussion started by: kshitij
8 Replies

9. Shell Programming and Scripting

Problem with awk script

Hi Can anyone help me in this Problem File1 ######################### HOLI 123 AND ONE TWO THREE AMITABH SAMSUNG POLI AND TWO SENSE CRYING WING PPIN TBFLAG I B AND OROLE TB_HOT=" DCT" TB_CAT=" CAT" TC_NOT=" AND" +PIN TB=" HOT" TB_GATE=" KOT" TB_LATE=" MAT" TC=LOT MAT DAT SAT... (5 Replies)
Discussion started by: kshitij
5 Replies

10. Shell Programming and Scripting

awk script Problem

I wrote a awk but doesnt work as expected. The Input File attached input file My awk Script /^.......*EXEC CICS /,/END-EXEC/ { if ( $0 ~ / LINK / ) { tsflag=1 } if ( $0 ~ /EXEC CICS/ && tsflag == 1 ) ... (6 Replies)
Discussion started by: pbsrinivas
6 Replies
Login or Register to Ask a Question