Korn Shell & Nawk...Filename changes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn Shell & Nawk...Filename changes
# 1  
Old 07-05-2011
Korn Shell & Nawk...Filename changes

I have the following piece of code:

Code:
 
 
YESTER=`TZ=aaa24 date +%b"-"%d`
 
filelist2=$(find /export/home/gen/check/logs \( -name \*$YESTER\* ! -name \*ADM\* \) -print | tr '\n' ' ')
 
nawk -F':' '
$2 ~ /Reason/ && $3 !~ /(PASSTHRU|OCAP|FP Power Button|Bootloader Reset)/ {
split(FILENAME, a, "-")
f = a[1]
while (i = index(f, "/")) f = substr(f, i+1)
sub("\r$", "");
printf("%s %s,%s %s,%s,%s,%s,%s-%s-%s-%s-%s-%s-%s-%s-%s\n", a[5], a[6], a[2], a[3], a[4], f, $0, f, a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9])
}' $filelist2 >> $OUTPUT

which basically looks in a certain directory for files that contain the word 'Reason' and splits the filenames, extracting pertinent information. Everything was working smashingly until the beginning of the month, as the date format changed from:

Code:
 
10.7.334.245-ADM-Cisco-Jun-30-12-11-22.txt

to

Code:
 
10.7.334.245-ADM-Cisco-Jul--1-13-22-33.txt.

Any suggestions as to how I can modify the code to accept BOTH types of dates?
# 2  
Old 07-05-2011
turning
Code:
 
10.7.334.245-ADM-Cisco-Jul--1-13-22-33.txt

into
Code:
 
10.7.334.245-ADM-Cisco-Jul-01-13-22-33.txt

Code:
 
YESTER=`TZ=aaa24 date +%b"-"%d | sed 's/--/-0/'`

---------- Post updated at 09:32 PM ---------- Previous update was at 09:29 PM ----------

is the trailing dot '.' expected in :
Code:
10.7.334.245-ADM-Cisco-Jul--1-13-22-33.txt.

??

Last edited by ctsgnb; 07-05-2011 at 04:56 PM..
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 07-05-2011
No...Sorry, my mistake... it should be:

Code:
 
10.7.334.245-ADM-Cisco-Jul--1-13-22-33.txt

---------- Post updated at 04:01 PM ---------- Previous update was at 03:53 PM ----------

Okay, thanks....the only problem is I need it to accept both types of dates because once July 10th rolls around the format will be 'Jul 10' and I do not want to have to manually change the code for this. Any suggestions would be appreciated...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Displaying trailing spaces in a filename; Korn Shell

Korn Shell on AIX 6.1 In one of our directories, we have 2 files with same names but one of those file's name has 3 trailing spaces ls *.ctl rconf.ctl rconf.ctl #this file has 3 trailing spaces Is there any way we could display these trailing spaces ? (6 Replies)
Discussion started by: polavan
6 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. UNIX for Dummies Questions & Answers

AWK & FILENAME

My file looks something like this: infile.seq I need to include the filename in each identifier, without the extension, and number them with consecutive numbers starting with 1. So, the expected outfile should look like this: I have been trying to modify the following code but I... (5 Replies)
Discussion started by: Xterra
5 Replies

5. Shell Programming and Scripting

Filename & Owner

Hi all! I'm trying to write a script that joins the filename and the owner (e.g. .profile_root , home_smith) Is there a easy way to do it. I've been trying with a for and playing with ls and head & tail. I would attach what I've had done but is very ugly:o (1 Reply)
Discussion started by: funyotros
1 Replies

6. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

7. UNIX for Advanced & Expert Users

nawk & awk

###----------------------TEST FOR $ Value------------------------ sort $RTF 2>>$LOG | nawk -F\| '\ { for( i=1; i<=NF; ) { if( i == NF ) { amt=substr($i,1,1) #$ value if (amt == /^ * /) printf( "$%s\n", $i ); ... (5 Replies)
Discussion started by: sd12
5 Replies

8. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

9. Shell Programming and Scripting

Korn Shell Script - Read File & Search On Values

I am attempting to itterate through a file that has multiple lines and for each one read the entire line and use the value then to search in other files. The problem is that instead of an entire line I am getting each word in the file set as the value I am searching for. For example in File 1... (2 Replies)
Discussion started by: run_unx_novice
2 Replies

10. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies
Login or Register to Ask a Question