Sponsored Content
Full Discussion: awk decrement loop
Top Forums Shell Programming and Scripting awk decrement loop Post 302735567 by Don Cragun on Sunday 25th of November 2012 03:46:13 PM
Old 11-25-2012
Note that according to the standards, setting FS to an empty string produces undefined results. (Doing so treats each character as a field in gawk and some other version of awk, but generates various errors or unexpected results on other versions of awk.) If I understand what shivacoder is trying to do, I think the following is a portable way to do what was requested:
Code:
awk -v c=4 '{
        for(i = c; i >= 1; i--) {
                # Print a header preceded by a <newline> if this is not the 1st
                # output line.
                printf("%sProcessing %d character strings from \"%s\".\n",
                        i != c || NR > 1 ? "\n" : "", i, $0)
                if(i > length($0)) {
                        printf("There aren'\''t %d characters in \"%s\".\n",
                                i, $0) 
                        continue
                }
                # Print the 1st line.
                printf("%s%s%s\n", substr($0, 1, i),
                        i == length($0) ? "" : "_", substr($0, i + 1))
                if(length($0) >= i)
                        for(j = 1; j + i < length($0); j++)
                                printf("%s_%s_%s\n", substr($0, 1, j),
                                        substr($0, j + 1, i),
                                        substr($0, j + i + 1))
                # Do not print the last line if it would duplicate the 1st line.
                if(i != length($0) / 2 && length($0) > i)
                        printf("%s_%s\n", substr($0, 1, length($0) - i),
                                substr($0, length($0) - i + 1))
        }
}' input


Last edited by Don Cragun; 11-26-2012 at 01:18 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While-loop with awk

Hi, I have recently posted in another thread started by me :D. But in an effort to make my script more beautiful I've been thinking abbout while loops. I run my script with the command: sh script 4 numbers.txt And my script is like this: data=`cat $2 | xargs -n $1` #echo $data ... (13 Replies)
Discussion started by: baghera
13 Replies

2. Shell Programming and Scripting

Can we increment or decrement a date value?

export a=`date` a=`expr $a + 1` Is it possible? if not how can i increment or decrement a date variable? (2 Replies)
Discussion started by: arghya_owen
2 Replies

3. Shell Programming and Scripting

decrement a four part number in shell script

I have a four part number eg: 1.21.1.3 I need to find a way in shell script to decrement this by one and put in a loop so the values printed will be 1.21.1.2 1.21.1.1 1.21.1.0 Which is the best way to do this in shell script?? (7 Replies)
Discussion started by: codeman007
7 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

Decrement using bash!!

Hi all, Thanks in Advance! I want a simple script to print today and yesterdays date. using this command date +%d%m%Y i can able get today's date but i want yesterday's date with the same format. so i tried using simple decrement operator but... (2 Replies)
Discussion started by: anishkumarv
2 Replies

6. Shell Programming and Scripting

Decrement one from 3rd Column

Hi, I need a script that will subtract 1 from the third column of the line beginning with %, leaving all other values the same. So 158 should be 157, 308 should be 307, 458 should be 457. Before: # 30109 xyz abc Data % 30109 158 5 8 2 000023f 01f4145 # 30109 ... (3 Replies)
Discussion started by: morrbie
3 Replies

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

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

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

10. Shell Programming and Scripting

awk for loop help

Hello, I have an input file that looks like so: 1 2 3 4 5 6 7 8 9 and I just want to print the first and third column (note: my actual file contains many many more fields so I don't want to use '{ print $NF }' for each field I want. I tried using: awk 'BEGIN {FS=" "} { for (i=1;... (13 Replies)
Discussion started by: Rabu
13 Replies
MAILQ(1)						      General Commands Manual							  MAILQ(1)

NAME
mailq - print the mail queue SYNOPSIS
mailq [-Ac] [-q...] [-v] DESCRIPTION
Mailq prints a summary of the mail messages queued for future delivery. The first line printed for each message shows the internal identifier used on this host for the message with a possible status character, the size of the message in bytes, the date and time the message was accepted into the queue, and the envelope sender of the message. The second line shows the error message that caused this message to be retained in the queue; it will not be present if the message is being processed for the first time. The status characters are either * to indicate the job is being processed; X to indicate that the load is too high to process the job; and - to indicate that the job is too young to process. The following lines show message recipients, one per line. Mailq is identical to ``sendmail -bp''. The relevant options are as follows: -Ac Show the mail submission queue specified in /etc/mail/submit.cf instead of the MTA queue specified in /etc/mail/sendmail.cf. -qL Show the "lost" items in the mail queue instead of the normal queue items. -qQ Show the quarantined items in the mail queue instead of the normal queue items. -q[!]I substr Limit processed jobs to those containing substr as a substring of the queue id or not when ! is specified. -q[!]Q substr Limit processed jobs to quarantined jobs containing substr as a substring of the quarantine reason or not when ! is specified. -q[!]R substr Limit processed jobs to those containing substr as a substring of one of the recipients or not when ! is specified. -q[!]S substr Limit processed jobs to those containing substr as a substring of the sender or not when ! is specified. -v Print verbose information. This adds the priority of the message and a single character indicator (``+'' or blank) indicating whether a warning message has been sent on the first line of the message. Additionally, extra lines may be intermixed with the recipients indicating the ``controlling user'' information; this shows who will own any programs that are executed on behalf of this message and the name of the alias this command expanded from, if any. Moreover, status messages for each recipient are printed if available. Several sendmail.cf options influence the behavior of the mailq utility: The number of items printed per queue group is restricted by MaxQueueRunSize if that value is set. The status character * is not printed for some values of QueueSortOrder, e.g., filename, random, modification, and none, unless a -q option is used to limit the processed jobs. The mailq utility exits 0 on success, and >0 if an error occurs. SEE ALSO
sendmail(8) HISTORY
The mailq command appeared in 4.0BSD. $Date: 2013-11-22 20:51:55 $ MAILQ(1)
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy