Use of -r, grep, nawk in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of -r, grep, nawk in script
# 1  
Old 03-06-2014
Use of -r, grep, nawk in script

Hello Friends,

I am new to unix shell, need to understand the meaning of few cmds in below script,

Code:
#!/usr/bin/ksh
FTP_FILE_NAME="$1"

if [ -r $FTP_FILE_NAME ]
then
  grep "TRLR@@@@@@" $FTP_FILE_NAME | nawk -F"[|]" '{print $2}'
else
  echo "0"
fi

what is the use of -r, grep, nawk & -F in above script. Why grep is followed by "TRLR@@@@".

Thx for your time.

Last edited by Franklin52; 03-06-2014 at 10:04 AM.. Reason: Please use code tags
# 2  
Old 03-06-2014
You could easily answer these question by doing some basic research. Namely into the man pages:
test
grep
nawk

"TRLR@@@@" is the search term. If you don't understand it, ask the person who wrote it.
# 3  
Old 03-06-2014
-r is a test for file existence (see man test)
if the file exists then grep is looking for "TRLR@@@@@@" in the file (see man grep)
and if it finds the string awk uses the "|" as a field separator to print the second field (see man awk)

Maybe you should try a little reading or research before just asking.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. Shell Programming and Scripting

Nawk Script not working

Any idea why this isn't working? YESTERF=`TZ=aaa24 date +%b"-"%d | sed 's/-0/--/'` filelist2=$(find /export/home/gen/cks/traces \( -name \*YESTERF\* -name \*DNA\* \) -print | tr '\n' ' ') print "Date/Time,Location,Shelf,IP,Reason,Log Filename" >> $OUTPUT nawk -F':' ' $2 ~... (2 Replies)
Discussion started by: ther2000
2 Replies

3. Shell Programming and Scripting

Var in nawk script parse incorrectly

I'm writing a Texas Hold'em script in bash v3.00.16(1) to learn more about awk/nawk scripts and regex expressions by trying to randomize a list of names using awk's rand function. The problem is that the elements in the var convert to a single element in the nawk script. I've tried several things,... (4 Replies)
Discussion started by: HexKnot
4 Replies

4. Shell Programming and Scripting

Error running nawk script

Hi, I was trying to use nawk script given in this link https://www.unix.com/aix/19979-df-output-not-aligned.html but when i do this im getting this error $ df -k|formatDF.nawk -ksh: formatDF.nawk: not found Can anyone help me on this... (6 Replies)
Discussion started by: niteesh_!7
6 Replies

5. UNIX for Dummies Questions & Answers

Loop in Nawk Script

I have a script which performs a getline (customer enters data) and a list is returned which has the data that was entered return to them. Then it ends. How can I get this script to return to the begin and ask the question again. Ths script needs to stop after the list is returned and then hit... (2 Replies)
Discussion started by: Morph797
2 Replies

6. Shell Programming and Scripting

grep / nawk issue

I have a report which contains the following: Count Value % 47 69.12 18 26.47 3 4.41 I want to grep the total on the bottom brackets and store in a variable. However this may have a different figure everyday. To read the i do: ... (1 Reply)
Discussion started by: Pablo_beezo
1 Replies

7. Shell Programming and Scripting

grep, awk, nawk combo

I have 2 files: File1 "aa","server","001-9031234-001", File2 001-9031234-001|12345 Both files have many lines of text. Each line needs to be evaluated. I need to look at the value of the third field in File 1. Then look for that same value in File 2 and assign the value of Field 2... (5 Replies)
Discussion started by: scriptr2be
5 Replies

8. UNIX for Dummies Questions & Answers

what is the similar command for "grep -v" in nawk?

Can any one please say about the below, using, grep -v "name" file.txt the result of above command will be it will print all the lines except the line which having the word "name" similarly, nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=1 s="name" file.txt ... (7 Replies)
Discussion started by: prsam
7 Replies

9. Shell Programming and Scripting

NAWK Script not working fine

Hello to all can any one help me out with a nawk script. Actually i am having a shell script which uses nawk pattern searching and it is not parsing the file properly. I have been debugging it since long time, but nt able 2 find the root cause.. If any one can help me out with this one .. (3 Replies)
Discussion started by: dheeraj19584
3 Replies

10. Shell Programming and Scripting

help need on nawk script

Dear experts I have a big file containing several profiles each flagged with "PROFILE" at the beginning of each one. I am trying to use the following command in cshell to seperate each profile and save each one in seperate file. I wrote a script as following: nawk -v i=0 '{if($1~/PROFILE/)... (5 Replies)
Discussion started by: Reza Nazarian
5 Replies
Login or Register to Ask a Question