Sponsored Content
Top Forums UNIX for Dummies Questions & Answers HELP - NEED Small Script ( or single awk Command) Post 302955155 by RavinderSingh13 on Tuesday 15th of September 2015 02:22:40 AM
Old 09-15-2015
Hello Nagarjuna4347,

No need to apologies, you can hit thank you button for any helpful post by any user in this forum to thank anyone. If I understood your requirement correctly then following may help you in same.
Code:
cat check_dates_files.ksh
VAL=$1
if [[ $VAL == "" ]]
then
        echo "No variable DATE passed, so exiting the script. FORMAT of variable should be YYYYMMDD form."
        exit;
fi
 
ls -lhtr CODS_ACTMZ_*${VAL}*TXT | awk -vs1="TRANS_ALL" -vs2="CTR_ACT" -vs3="REF_NHA" '{if($NF ~ s1){print $NF OFS $5 OFS "TRANSACTIONS"};if($NF ~ s2){print $NF OFS $5 OFS "CTR_ACCOUNT"};if($NF ~ s3){print $NF OFS $5 OFS "ACCOUNT"}}'

Above script name is check_dates_files.ksh give proper permissions to it and run it, in my case I have created some test files as follows.
Code:
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_NHP_ALL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_NHA_ALL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_CTR_RE_MIL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_CTR_PE_MIL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_CTR_IN_MIL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 14 06:45 CODS_ACTMZ_REF_CTR_BR_MIL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1  146 Sep 14 12:49 CODS_ACTMZ_REF_CTR_ACT_MIL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1  515 Sep 14 12:51 CODS_ACTMZ_TRANS_ALL_20150911.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 15 02:14 CODS_ACTMZ_REF_CTR_RE_MIL_20150912.TXT
-rw-r--r-- 1 Singh1 Singh1    0 Sep 15 02:14 CODS_ACTMZ_REF_CTR_PE_MIL_20150912.TXT

Then after running script we will get following.
Code:
./check_dates_files.ksh 20150911
CODS_ACTMZ_REF_NHA_ALL_20150911.TXT 0 ACCOUNT
CODS_ACTMZ_REF_CTR_ACT_MIL_20150911.TXT 146 CTR_ACCOUNT
CODS_ACTMZ_TRANS_ALL_20150911.TXT 515 TRANSACTIONS

Also when not passing any variables then following output will come to user.
Code:
 ./check_dates_files.ksh
No variable DATE passed, so exiting the script. FORMAT of variable should be YYYYMMDD form.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help to debug a small shell script (maybe AWK problem)?

Hi Buddies, The following is shell scripts which was borrowed from linux box for load average check. it runs good. (this structure is simple, when load average is too high, it will send alert to user) #!/usr/bin/ksh # Set threshold for 1, 5 and 15 minture load avarage # configured for... (4 Replies)
Discussion started by: GreatJerry
4 Replies

2. Shell Programming and Scripting

Help with awk script, changing the FS for a single variable

Hi all, im new to awk and would apreciate if you could tell me how to do this, i have a file with several entries like this: 2008-09-09 21:57:45 44 403 CUSTOM_EVENT Upgrade - end1 2008-09-09 21:57:46 45 403 CUSTOM_EVENT Component Check - start... (3 Replies)
Discussion started by: sx3v1l_1n51de
3 Replies

3. Shell Programming and Scripting

Multiple pipes toward a single awk command

Hello, I would like to pipe two variables into awk, but I don't know how to do. Each variable, "a" and "b", are in fact a list of data. They are not files. So to get awk to work with it I am using: echo $a | awk 'FNR==NR{print $1}FNR!=NR{print $4}' The above works, but when I am... (5 Replies)
Discussion started by: jolecanard
5 Replies

4. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

5. Shell Programming and Scripting

How can i use single quotes for SQL command in shell script

Hi. please help me to write the following query in a shell script. the Query is :select no,salary from emp_info where name='$var_name' the following is my code. #! /bin/sh var_name=$1 sqlplus -s user/pwd@DB << EOF select no,salary from emp_info where name="'$var_name'";... (4 Replies)
Discussion started by: little_wonder
4 Replies

6. Shell Programming and Scripting

How to alias an awk command with single and double quotes?

Hi, I am trying to write the following command as an alias in my .bashrc file. bjobs -u all | awk '{if (NR > 1) {username++;}}END{{print"\nJOBS BY USER:\n"} for (i in username) {print username,i;}{print"\n Total Jobs=",NR-1,"\n" }}' The command simply puts how many jobs each user is... (2 Replies)
Discussion started by: jacekmaciek
2 Replies

7. UNIX for Dummies Questions & Answers

single output of awk script processing multiple files

Helllo UNIX Forum :) Since I am posting on this board, yes, I am new to UNIX! I read a copy of "UNIX made easy" from 1990, which felt like a making a "computer-science time jump" backwards ;) So, basically I have some sort of understanding what the basic concept is. Problem Description:... (6 Replies)
Discussion started by: Kasimir
6 Replies

8. Shell Programming and Scripting

small sed script on command line.

Can anyone help me get this small sed script to work in shell on the command line? I need it in a one liner really as i want to edit many scripts in a for loop and dont want to have to invoke a separate script each time. #!/bin/sh sed '/mailx\ -s.*$ { i\ #Comment above mailx line ... (5 Replies)
Discussion started by: lavascript
5 Replies

9. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

10. Shell Programming and Scripting

Require single command to start script in multiple servers

I have 9 servers, on each server a script with common name is available. I send a token file to all server from 1 particular server. so when a daemon job checks that token file is available then it triggers the script.. I want to know is there any command or script which I will run/execute on... (16 Replies)
Discussion started by: mirwasim
16 Replies
All times are GMT -4. The time now is 02:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy