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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers what is the similar command for "grep -v" in nawk?
# 1  
Old 12-05-2008
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[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=0 a=1 s="name" file.txt

from above command i wil get the output as,
it will print all the lines which having "name" word and also the next line to it.

What i want is, similar to grep -v what is the option for nawk to get the output as , other lines EXCEPT the word "name" and the next line to it in nawk.
# 2  
Old 12-05-2008
Code:
awk '!/name/{print}' filename

this will print all the lines which doesnot contain "name"

Code:
awk 'c-->0;/name/{c=1}' filename

this will print all the next line where the pattern "name" is found
# 3  
Old 12-05-2008
Thanks vidyadhar85 for ur reply but i need to print all the lines except the line havin word and its next line..

u gave seprate commands but i need a single command which does both the thing.
# 4  
Old 12-06-2008
oh got your problem use this sed code this won't print the lines containing pattern "name" and its immidiate next line Smilie
Code:
home> sed '
> /name/{
> N
> /\n/d
> }' inputfile

good question Smilie
# 5  
Old 12-06-2008
#!/bin/ksh
i=`date +%d`
sed `/WARNING:Below field is not in File name/{N/\n/d}' load.$i >> load_new.txt


Using ur script i gave lik above but i am getting the following error,
-----------
/WARNING:Below: not found
-----------

I am seraching for "WARNING:Below field is not in File name" in load.<current day> and the next line of it and then redirecting tat o/p to load_new.txt

coul u please help me out?

Last edited by prsam; 12-06-2008 at 03:19 AM.. Reason: left the word "next line"
# 6  
Old 12-06-2008
buddy write it in this way and you used backstick "`" after sed make it single quote "'"
Code:
#!/bin/ksh
i=`date +%d`
sed '
/WARNING:Below field is not in File name/{
N
/\n/d
}' load.$i >> load_new.txt

# 7  
Old 12-06-2008
Thanks Tutor. It worked fine.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Advanced & Expert Users

Command similar to "touch" for modify File size

Hi All, I'm trying to find a command like similar to "touch" which would let me change the file size property. For ex: I have a file of size 1MB using the command i would like to set/update the size something like 1KB. Is it possible? Is there any such command which would accomplish this... (3 Replies)
Discussion started by: sriharshareddyk
3 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question