The function of substr clause in awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The function of substr clause in awk command
# 1  
Old 10-31-2009
Lightbulb The function of substr clause in awk command

Hello all,

Please help me in letting me know the function of *substr* function in awk...

actually i am new with this function i can play with awk but for this function needs your help in making me understand the correct way of using it.

I am writting a code please advice regarding this prespective.

Code:
 
#!/bin/sh
YESTERDAY=`head -1 /tmp/prv_date` \\ prv_date contains (e.g. 2009-10-30)
cd /tmp
cat ~scu/temp/man*.old ~scu/temp/man*.run | awk -F":" -v today=$YESTERDAY 'BEGIN{c=0;dc=0;} 
FNR{dc=c;
if(c==0 && substr($0,12,16)=="Date: "today) {c++;}; 
if(dc==1 && substr($0,12,6)=="Date: " && substr($0,18,10)!=today) {c=0;dc=0;};
if(c==1 && (substr($0,26,13)=="Platform CAPS" || substr($0,26,13)=="Over max CAPS")) {print $0}; }' > output$YESTERDAY.txt

Quote:
please explain line by line if possible, especially (FNR and substr) function
# 2  
Old 10-31-2009
You can find the answer and many more here:

The AWK Manual - Table of Contents
The GNU Awk User's Guide

Regards
# 3  
Old 10-31-2009
Thanks Franklin52,

But for a descripton regarding my query is still unsloved as i cannot find any details regarding substr function.

Dear All,

Please help
# 4  
Old 10-31-2009
# 5  
Old 10-31-2009
-----
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk and substr

Hello All; I have an input file 'abc.txt' with below text: 512345977,213458,100021 512345978,213454,100031 512345979,213452,100051 512345980,213455,100061 512345981,213456,100071 512345982,213456,100091 512345983,213457,100041 512345984,213451,100011 I need to paste the first field... (10 Replies)
Discussion started by: mystition
10 Replies

2. Shell Programming and Scripting

help required for 'expr substr' function

hi iam trying to extract a certain portion of the string whose value is stored below,but am getting syntax eror.The command is shown below for file in GMG_BASEL2*.txt do m1= cat reporting_date.txt year= expr substr $m1 1 2 echo $year done m1 has date 10/31/2009 but this vale... (6 Replies)
Discussion started by: jagadeeshn04
6 Replies

3. UNIX and Linux Applications

Print date at END clause of AWK

Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja. My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a... (4 Replies)
Discussion started by: fmeriles
4 Replies

4. Shell Programming and Scripting

use of substr function in awk

i want to get substring of second coloum of an file using awk substring function.please help me out (2 Replies)
Discussion started by: RahulJoshi
2 Replies

5. Shell Programming and Scripting

how to pass variable in NR function used in awk command?

Hi I want to pass variables with the NR function in awk command. test_file1 is input file having 500 records. var1=100. var2=200 awk -F" " 'NR >= $var1 && NR <= $var2' test_file1 > test_file2. My end result should be that test_file2 should have records from line number between... (2 Replies)
Discussion started by: Nishithinfy
2 Replies

6. UNIX for Dummies Questions & Answers

substr function in perl

Hi friends, I have written a perl code and it works fine but I am not sure tommorow it works or not, please help me. problem : When diff is 1 then success other than its failure but tomorrow its 20090401 and the enddate is 20090331. thats why I write the code this type but it does not work and... (1 Reply)
Discussion started by: tukuna82
1 Replies

7. Shell Programming and Scripting

having trouble with using if clause in AWK

The goal: I have a list of people in teams. The list looks something like this $1 = Job Position (marketing, IT, PR) $2 = Name $3 = Team Name $4 = Targeted member (somebody in field 2 targets somebody else) $5 = Employment Status (full time/part time/etc) The idea is to search through... (2 Replies)
Discussion started by: MaestroRage
2 Replies

8. Shell Programming and Scripting

awk substr

Hi I have multiple files that name begins bidb_yyyymm. (yyyymm = current year month of file creation). What I want to do is look at the files and where yyyymm is older than 1 month I want to remove the file from the server. I was looking at looping through the files and getting the yyyymm... (2 Replies)
Discussion started by: colesga
2 Replies

9. Shell Programming and Scripting

if clause in AWK END block not working.

Hello all... I have a slight problem in my awk script... I have a script which checks a csv file and keeps a count of any invalid records and then if it finds any, exits with a code of 1. problem is it dosnt seem to work properly :rolleyes: Everthing seem to work interms of the stats output,... (1 Reply)
Discussion started by: satnamx
1 Replies

10. Shell Programming and Scripting

Trouble using substr function with Bourne shell script

Hi, I'm a newbie to UNIX scripting and I'm having some trouble compiling my script. I'm using the Bourne Shell and cannot seem to use the substr function correctly. I'm trying to extract the last two digits of a year that's stored in a variable based off of a condition. I've searched the... (4 Replies)
Discussion started by: E2004
4 Replies
Login or Register to Ask a Question