Sponsored Content
Full Discussion: using awk loop
Top Forums Shell Programming and Scripting using awk loop Post 302517978 by ken002 on Thursday 28th of April 2011 11:18:05 AM
Old 04-28-2011
using awk loop

Hi, Gurus,
I have a requirement as following:
source data:
Code:
103,8,25

I want to get
Code:
103 8 25 1_8
103 8 25 9_16
103 8 25 17_24
103 8 25 25_32
103 8 25 33_40
103 8 25 41_48
103 8 25 49_56
103 8 25 57_64
103 8 25 65_72
103 8 25 73_80
103 8 25 81_88
103 8 25 89_96
103 8 25 97_104
103 8 25 105_112
103 8 25 113_120
103 8 25 121_128
103 8 25 129_136
103 8 25 137_144
103 8 25 145_152
103 8 25 153_160
103 8 25 161_168
103 8 25 169_176
103 8 25 177_184
103 8 25 185_192
103 8 25 193_200
103 8 25 201>

It is 26 records, last record is 201>

currently, I am using following command

Code:
awk  -F',' '{for(i=1; i<=$3+1; i++)print $1","$2","$3","((i-1)*$2+1)"_"$2*i}'

i got most of it, only last record is
Code:
103, 8, 25, 201_208.

Smilie
can anyone help me out.

Thanks in advance.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-28-2011 at 12:28 PM.. Reason: code tags, please!
ken002
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using AWK in a for loop

Hello, I am trying to use AWK to print only the first field of numerous text files, and then overwrite these files. They are of the format 1*2,3,4,5. I have tried the following code (using tcsh): foreach f (file1 file2 file3) cat $f | awk -F'*' '{print $1}' > $f end However, I get very... (4 Replies)
Discussion started by: Jahn
4 Replies

2. UNIX for Dummies Questions & Answers

for loop in awk?

I am new to unix and have pieced together two scripts that work independently. The first checks all the filesystems and reports which are running low on space. df -m | awk 'int($4) > 75 { print $1 " has only " $3 "mb free from a total of " $2 ", this filesystem is " $4 " full! \n" }... (1 Reply)
Discussion started by: Bdawk
1 Replies

3. Shell Programming and Scripting

awk for-loop and NR

Hey, I know this is a stupid question, but it doesn't work. I have a file with 10 lines and I want to pipe the content to awk and then print line 1 til 2 into another file and then line 3-4 ... So my script looks like that, but doesn't work: cat grid_ill.pts | awk '{ for (NR=1;NR<3;NR++)... (8 Replies)
Discussion started by: ergy1983
8 Replies

4. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies

5. Shell Programming and Scripting

awk - loop from a to z

Hello, I was wondering if it is possible to do a loop on letters rather than numbers with awk (gawk). Basically I used to do: echo "nothing" | gawk '{for(i=1;i<11;i++)print i}' But I would like to do something like that (which obviously does not work): echo "nothing" | gawk '{for(i in... (6 Replies)
Discussion started by: jolecanard
6 Replies

6. Shell Programming and Scripting

awk loop and using shell in awk

Hi, everyone! I have a file, when I print its $1 out it show several strings like this: AABBCC AEFJKLFG FALEF FAIWEHF What I want to do is that, after output of each record, search the string in all files in the same folder, print out the record and file name. This is what I want... (4 Replies)
Discussion started by: xshang
4 Replies

7. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

8. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

9. UNIX for Beginners Questions & Answers

awk with For loop

Hi My Requirement is to take the sum of each column below is the input file. 1 2 3 4 1 2 3 4 1 2 3 4 Initial i was using below command to achieve my desired result. however this was adding the row and not column. i am not able understand why this is happening awk... (1 Reply)
Discussion started by: scriptor
1 Replies

10. UNIX for Beginners Questions & Answers

awk !seen[$]++ in else loop

Hi all, I was searching the net for a solution for my problem... unfortunately nothing so far. I want to sort on more than on column tab delimited file and keep the line if in the column I sort there is no value, but for those who have a value I want them only unique. I have tried the... (5 Replies)
Discussion started by: ksenia
5 Replies
scroll(3NCURSES)														  scroll(3NCURSES)

NAME
scroll, scrl, wscrl - scroll a curses window SYNOPSIS
#include <curses.h> int scroll(WINDOW *win); int scrl(int n); int wscrl(WINDOW *win, int n); DESCRIPTION
The scroll routine scrolls the window up one line. This involves moving the lines in the window data structure. As an optimization, if the scrolling region of the window is the entire screen, the physical screen may be scrolled at the same time. For positive n, the scrl and wscrl routines scroll the window up n lines (line i+n becomes i); otherwise scroll the window down n lines. This involves moving the lines in the window character image structure. The current cursor position is not changed. For these functions to work, scrolling must be enabled via scrollok. RETURN VALUE
These routines return ERR upon failure, and OK (SVr4 only specifies "an integer value other than ERR") upon successful completion. X/Open defines no error conditions. This implementation returns an error if the window pointer is null, or if scrolling is not enabled in the window, e.g., with scrollok. NOTES
Note that scrl and scroll may be macros. The SVr4 documentation says that the optimization of physically scrolling immediately if the scroll region is the entire screen "is" per- formed, not "may be" performed. This implementation deliberately does not guarantee that this will occur, to leave open the possibility of smarter optimization of multiple scroll actions on the next update. Neither the SVr4 nor the XSI documentation specify whether the current attribute or current color-pair of blanks generated by the scroll function is zeroed. Under this implementation it is. PORTABILITY
The XSI Curses standard, Issue 4 describes these functions. SEE ALSO
ncurses(3NCURSES), outopts(3NCURSES) scroll(3NCURSES)
All times are GMT -4. The time now is 04:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy