awk command syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command syntax
# 1  
Old 08-26-2009
awk command syntax

I want the output to show 2 lines following this line.
How do I amend my awk command.
Please guide.
Thanks


Quote:
root@myserver:/# iostat -En | awk '/c1t20d0/ {print}'
c1t20d0 Soft Errors: 1 Hard Errors: 0 Transport Errors: 0
root@myserver:/#
# 2  
Old 08-26-2009
Code:
iostat -En | nawk '/c1t20d0/ {c=2;next} c && c--'

# 3  
Old 08-26-2009
thanks awsome

---------- Post updated at 09:26 AM ---------- Previous update was at 09:17 AM ----------

What if I want the output to look like this using the awk command
Quote:
c1t23d0 Soft Errors: 79 Hard Errors: 100 Transport Errors: 22
Vendor: SEAGATE Product: ST373405FC Revision: 0005 Serial No: 3EK0GGBL
Size: 73.40GB <73404694528 bytes>
Media Error: 79 Device Not Ready: 0 No Device: 21 Recoverable: 79
Illegal Request: 0 Predictive Failure Analysis: 0


---------- Post updated at 09:30 AM ---------- Previous update was at 09:26 AM ----------

ok I got it the command should look like this
Quote:
root@myserver:/# iostat -En | nawk '/c1t23d0/ {c=4} c && c--'
c1t23d0 Soft Errors: 79 Hard Errors: 100 Transport Errors: 22
Vendor: SEAGATE Product: ST373405FC Revision: 0005 Serial No: 3EK0GGBL
Size: 73.40GB <73404694528 bytes>
Media Error: 79 Device Not Ready: 0 No Device: 21 Recoverable: 79
root@myserver:/#
# 4  
Old 08-26-2009
Code:
iostat -En | nawk '/c1t20d0/ {c=5} c && c--'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting syntax error while running awk command

Hello Gurus, I am firing the below command : df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}' But I am getting the below error:- ====== syntax error The source line is 1. The error context is {if ($4 > >>> 90%) <<< awk: The... (9 Replies)
Discussion started by: pokhraj_d
9 Replies

2. Shell Programming and Scripting

Help with the awk syntax

Hello Experts: While writing a script to help one of the posts on here, I end up writing a wrong one. I am very much eager to know how this can be corrected. Aim was to not print specified columns - lets say out of 100 fields, need to print all but 5th, 10th, 15th columns. Someone already... (13 Replies)
Discussion started by: juzz4fun
13 Replies

3. Shell Programming and Scripting

awk syntax

Hi I have a bash file which will split a big file to many small files. But I got a syntax error.H="$(head -1 CCC.tped)" awk 'print $0 > $1 ".tped"' CCC.tped for f in $(ls *.tped); do echo "$H\n" "$(cat $f)" >$f; done And -bash-4.1$ bash split awk: print $0 > $1".tped" awk: ^ syntax error... (3 Replies)
Discussion started by: zhshqzyc
3 Replies

4. HP-UX

ps command syntax

I use hp HP-UX. I want to get vsz of the process . What is the syntax ... /run>ps -help ps: illegal option -- h ps: option requires an argument -- p usage: ps (3 Replies)
Discussion started by: chuikingman
3 Replies

5. AIX

Help with syntax using AWK

I have a file which is comma separated and has quotes. I can use this command and awk -F"," '{ if ($4=="01" print $0 }' test.txt But this doesn't fetch me the data.since it has quotes. If the data has no quotes,the above command works fine. In Unix you can skip quote \" but this doesn't work.... (7 Replies)
Discussion started by: ganesnar
7 Replies

6. Shell Programming and Scripting

AWK syntax help

i have a ksh code that needs to be written in AWK. can someone please help me here? :( if }" | grep -c "$2") -gt 0 ] ; then print - "found $2 in array ignore" else print - "did not find $2 in array ignore" fi ignore=4ty56r ignore=er45ty . . . ignore=frhtg2 (27 Replies)
Discussion started by: usustarr
27 Replies

7. UNIX for Dummies Questions & Answers

awk syntax

Little bit confusing while using awk :confused::confused: In Sed while pattern search we can use "(double quotes) i mean $a=hello $cat file.txt |sed -n "/$a/p"this thing work fine But if i use it in awk it's not working How could i do the substitution of pattern by a variables and the... (1 Reply)
Discussion started by: posix
1 Replies

8. Shell Programming and Scripting

AWK syntax

Hi I am trying to understand AWK syntax so I tried this command which gives me the home directory of root awk 'BEGIN { FS = ":"} {if ($1 == "root") print $6 }' /etc/passwd I would know what are the following commands doing. The first one prints all /etc/passwd, second prints nothing. ... (4 Replies)
Discussion started by: wakatana
4 Replies

9. Shell Programming and Scripting

awk syntax help

I don't get correct output when I run this command line: nmap -sP failedhost.com | grep -i failed | awk -F '{print $6}' I basically want it to return 'failedhost.com' but its just showing the output of the nmap scan. (8 Replies)
Discussion started by: streetfighter2
8 Replies

10. Shell Programming and Scripting

Help with Awk Syntax

I have written many awk commands which go in multiple lines. I have this confusion many times. Some time they work if i dont terminate them with "\" but some time error. Some time in "if" statements between if and else if i dont use ";" it gives error but sometimes it doesnt. The below... (4 Replies)
Discussion started by: pinnacle
4 Replies
Login or Register to Ask a Question