Visit The New, Modern Unix Linux Community


Please explain the use of quotes in awk command in below example-


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Please explain the use of quotes in awk command in below example-
# 1  
Question Please explain the use of quotes in awk command in below example-

Example:

Code:
`abc.ksh | grep '^GLIS'| awk -F' ' '{print \$1}'`;

# 2  
Hello Tanu,

It's a kind request to be more clear into your questions, however could you please go through following and let us know if this helps you.
Code:
`abc.ksh                  ####Your script, not sure about it what it does and what output it gives. So it runs here.
|                         ####using pipe here so that above script's standard output, re-directing to next command as standard input.
grep '^GLIS'              ####In abc.ksh's output using grep(to search strings) where any line is starting with string GLIS swarch all those lines.
|                         ####Again using pipe to send previous command's standard output to next command as standard input.
awk -F' ' '{print \$1}'`; ####Using awk here, where -F' ' defines the delimiter is space. Printing the first field here by using $1.

Also in above code there is no need for doing \$1it should be good with $1if you are not using it with commands like sshetc.
EDIT: Edited my explanation above where I mentioned line not starting, changed it to line starting now, I had a typo there. Thanks to greet_sed, corrected it now.

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-29-2016 at 12:25 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Thanks Ravinder. I thought single quotes (' ') had some issue in my command but it was \ (as you mentioned).

In perl script it works with \ (like \$1) only but in shell script no need of \ (simple $1).

Thanks again.
# 4  
Hi Ravinder,

$ grep '^str' looks for a word call ed "str" in the beginning of a line .

May be it is just a typo in your post.
This User Gave Thanks to greet_sed For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #143
Difficulty: Easy
Apple released a Unix system called Darwin in 2000 which became the core of the Mac OS X operating system, which was later renamed macOS.
True or False?

10 More Discussions You Might Find Interesting

1. Red Hat

Please help to explain the command

su - keibatch -c ""date ; /usr/local/kei/batch/apb/bin/JKEIKYK4140.sh -run "&$C$6&" WSUKE100201"" Not clear about : date ; /usr/local/kei/batch/apb/bin/JKEIKYK4140.sh -run "&$C$6&" WSUKE100201 Please help (2 Replies)
Discussion started by: honda_city
2 Replies

2. Shell Programming and Scripting

Explain awk

I have 2 files recevied abc def ghi totallist abc 123 jasdhfaj def 345 fjdgkfsfh ghi 567 dfjdhdhfj jkl 678 djkahfdjshdf xyz 984 jdfdhfhdh myOutputFile jkl 678 djkahfdjshdf xyz 984 jdfdhfhdh I used this command for the output : awk 'FNR==NR {f1;next} !($1 in f1)' recevied... (2 Replies)
Discussion started by: nani1984
2 Replies

3. UNIX for Dummies Questions & Answers

Please explain this command?

Hi, I saw this. But I don't know why we need this? ls mydir > foo.txt ## I know what this will do, it will take the results and write to the file called foo.txt ls mydir > foo.txt 2>&1 ## Don't know why we need 2>&1 Thanks. (2 Replies)
Discussion started by: samnyc
2 Replies

4. Shell Programming and Scripting

Explain this awk

found this handy one liner in another thread which is closed, it does what i need but im trying to understand it. it basically matches the field that contains the value v and prints its position awk -F, '{for(i=1;i<=NF;i++)if($i==v)print i}' v=yourfield inputfile my understanding is assign... (3 Replies)
Discussion started by: jack.bauer
3 Replies

5. Shell Programming and Scripting

Can Any people explain this awk command

Dear all , Can any people explain this awk command? What is the purpose of if (v++){b=$i;$i=""}? awk -F, '{for (i=1;i<=NF;i++){if (v++){b=$i;$i=""}};print $0} END { print "dups are" ;for ( i in b) print i}' OFS="," input_file This script is used to replace column duplicate value ... (1 Reply)
Discussion started by: eldonlck
1 Replies

6. Shell Programming and Scripting

Please Explain me this command

find . -type f -ctime +3 -exec mv {} /somedirectory/ \; in particular "-ctime v/s -mtime" and "difference between +3 and -3" (5 Replies)
Discussion started by: Rambo
5 Replies

7. 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

8. UNIX for Dummies Questions & Answers

Can anyone explain what this command is doing?

Specifically what is the purpose of sed? What is f? Why is the 'cp f $phonefile' line needed when the script ‘goes live'? Why might that two commands following sed be commented out at the present time ( i.e., during development)? Thanks in... (2 Replies)
Discussion started by: knp808
2 Replies

9. Shell Programming and Scripting

please explain the command

Hi all , please explain the following command : perl -e 'select(undef,undef,undef,.15)' Thanks and Regards Navatha (2 Replies)
Discussion started by: Navatha
2 Replies

10. Shell Programming and Scripting

Explain awk

Hi, I found this command in this forum, but, couldnt understand much from it. could any one help me understand that??? the commands are : awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2 awk '{sub(/~ */,x);printf $0(/\|$/?ORS:x)}' awk '{sub(/~ */,x);sub(/\|$/, "|\n")}8'... (4 Replies)
Discussion started by: hitmansilentass
4 Replies

Featured Tech Videos