AWK SCRIPT HELP : INCREMENTING PROBLEM


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK SCRIPT HELP : INCREMENTING PROBLEM
# 1  
Old 03-13-2011
Network AWK SCRIPT HELP : INCREMENTING PROBLEM

Hi Guys ,

I am having one command file like this

FILE1

################################

Code:
 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", p) }}1' output >> out9

awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", p) }}1' output >> out9

awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", p) }}1' output >> out9

awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", p) }}1' output >> out9

awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", p) }}1' output >> out9

################################################

I want to Increment the variable "p" like to have the Expected output as shown below

OUTPUT FILE

#############################################
Code:
 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", 1) }}1' output >> out9

 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", 2) }}1' output >> out9

 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", 3) }}1' output >> out9

 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", 4) }}1' output >> out9

 
awk '/output/ {a[FNR]=$2}   {for(i=1;i<=NF;i++)  { gsub("i1", i) ; gsub("i2",++i) ; gsub("P1", 5) }}1' output >> out9

############################################

Increment p to 1 , 2 ,3 4 and 5 kind of

I am using this awk script as shown below

awk {for(i=0;i<=5;i++) {gsub("p",i) }}' FILE1

But I am getting same value like 0 in the Output file

How will it be incremented

Thanks
Jaita
# 2  
Old 03-13-2011
Try this,
Code:
awk '!/^$/{gsub("p",++j)}1' inputfile

# 3  
Old 03-13-2011
Try

Code:
awk 'BEGIN{i=1} !/^$/{ gsub("p",i++) ; print }' 12.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Incrementing the date depending on the Counter (parameter) passed to the script

Hello Everyone, I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server. i.e. Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4). First I will check for the... (1 Reply)
Discussion started by: filter
1 Replies

2. 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

3. Shell Programming and Scripting

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 ... (5 Replies)
Discussion started by: jaita
5 Replies

4. Shell Programming and Scripting

Facing problem in incrementing the variable

When I did, echo $SHELL in cmd prompt of putty, its displaying /bin/sh And in my shell script., I hav started with., #!/bin/sh and i=1; while ; do . . . i=$; (9 Replies)
Discussion started by: av_vinay
9 Replies

5. 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

6. Shell Programming and Scripting

Problem with AWK script

Help Please I have 2 files. each file contain 2 columns.1st file 1st column contain symbols (keys-a1..a22..a-x,a-y) and 1st file 2nd column contain values (any like 2344,434323). Secondfile also the same but the values are may be different or not and the symbols (keys) are same but may be... (0 Replies)
Discussion started by: repinementer
0 Replies

7. Programming

Interesting Problem About Incrementing ++

Here is my code: int startingPort = 200; string tempPort; stringstream out; out<<startingPort; tempPort = out.str(); //tempPort carries startingPort in string format //convert tempPort to *char - currentPort going to be passed into getaddrinfo() char currentPort;... (10 Replies)
Discussion started by: f.ben.isaac
10 Replies

8. UNIX for Dummies Questions & Answers

can anybody help me out in writing the script for incrementing the specific field

can anybody help me out in writing the any script (awk,shell or perl script) for incrementing the specific field highlighted below /{/data/{/assetMetricsList//{1]/dailyCount,........./{/data/{/assetMetricsList//{100]/dailyCount It should be in below format in oneline seperated by commas ... (1 Reply)
Discussion started by: swapnak
1 Replies

9. Shell Programming and Scripting

shell script help: sorting, incrementing environment variables and stuff

First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info. I'm writing a shell script to automate the setup of a flash 'page flip'. My current code is below. the page flip takes an xml file of format <content> <pages... (1 Reply)
Discussion started by: secoif
1 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