Adjustment to current awk statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adjustment to current awk statement
# 1  
Old 06-18-2014
Adjustment to current awk statement

Hello all,

I have a script that currently works very well but I would like to make a change so that I could prompt for user input for a 2 digit numeric field that would represent the month instead of using the system date for the month.
This is my current awk script that Don so graciously helped me create.
Code:
awk -v my=`(date +%m%y)` -F'[^[:digit:]]*' ' {       out = out $0 "\n" } /Account Number:/ {         CN = $2         if(lCN != CN) {                 if(fn != "") close(fn)                 fn = sprintf("%d%s.txt", lCN = CN, my)         }         next } /\f/ {  printf("%s", out) > fn         out = "" } END {   if(fn != "") close(fn) }' input2

# 2  
Old 06-18-2014
If an awk statement is four screens wide, it does not count as a one-liner and should not be crammed onto one line.


Code:
my=""

while true
do
        case "$my" in
        [0-9][0-9]) break ;;
        *)
                printf "%s" "Enter 2 digits: "
                read my
                ;;
        esac
done

awk -v my="$my" -F'[^[:digit:]]*'  '{       out = out $0 "\n" }
/Account Number:/ {
         CN = $2
         if(lCN != CN) {
                 if(fn != "") close(fn)
                 fn = sprintf("%d%s.txt", lCN = CN, my)
         }
         next }

/\f/ {  printf("%s", out) > fn
         out = "" }

END {   if(fn != "") close(fn) }' input2

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Chromosomal Bin Size Adjustment

Dear All, Hope you are rocking. I was using publicly available tools to do a task to chop a region into equal number of bins. But the glitch with this tool is that it causes the last region to carry lower number of bases than requested. But I want the first bin to have the lower ones. Here... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

3. Shell Programming and Scripting

awk adjustment to print total

im trying to print all lines in the /var/log/syslog file that contain the pattern CRON. and after all the lines have been printed, i want a total of all the lines that contained "CRON" to be printed at the end. the below command is printing the correct lines, but it is giving me the sum of all... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

IF statement dealing with current time

Hi Guys, I am trying to put together a script that will search a txt file for a timestamp and select all text after the initial one up to EOF but the timestamp searched for will depend on the current date So if it the current time is between 0600 and 0700 the script will search a text file... (7 Replies)
Discussion started by: martin0852
7 Replies

5. UNIX for Advanced & Expert Users

current directory in awk

Hello, I want to use the string with the current directory in my awk command. I tried: 'pwd=system("pwd")' but it doesn't work. can please help somebody? (2 Replies)
Discussion started by: daWonderer
2 Replies

6. Shell Programming and Scripting

AWK Compare previous value with current.

Hi, I have one small doubt how to go ahead and process the below requirement. File Content 1,abc,10 2,xyz,11 3,pqr,12 4,pqr,13 5,pqr,14 Output file expected: 1,mnq,1 1,ddd,2 1,qqq,3 1,sss,4 1,ddd,5 1,eee,6 1,fff,7 1,ddr,8 1,rrd,9 (3 Replies)
Discussion started by: dikesm
3 Replies

7. UNIX for Dummies Questions & Answers

Using current line in a command in AWK

Hi, Im trying to get current line in the AGREP command I use in AWK. My script looks like this: list.txt car bus checklist.txt cer buss cat list.txt | awk -v mycmd="$(agrep -2 -i $0 checklist.txt)" '{print $mycmd}' It doesnt work. How can I get the current line in the $0... (6 Replies)
Discussion started by: m4rty
6 Replies

8. Ubuntu

Brightness adjustment

Hi all, I am using Ubuntu 10.04 LTS in Samsung N148. I can't see any option to adjust brightness in System->Preference->monitor. Is there any shell command to adjust brightness ? I have used xgamma -gamma but it change the gamx not brightness. Cheers (7 Replies)
Discussion started by: gvj
7 Replies

9. HP-UX

How to disable time auto adjustment ??

We do not use ntp.conf file. However time's changed automatically. How can i disbale automatic time adjustment ? Thank you in advance. (6 Replies)
Discussion started by: v838
6 Replies
Login or Register to Ask a Question