Egrep how to make sure string is after 5 comma


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Egrep how to make sure string is after 5 comma
# 8  
Old 10-14-2013
echo a,b,c,d,e,f,g,h,i | awk 'NR>5 && $1~/f/ {print "yes"}' RS=,

I guest $5~/f/ { print $0 } would print the record if the fifth column has f in it.
# 9  
Old 10-14-2013
I am going to assume that with "after 5th comma" you mean that letter "f" should be in the 6th (comma separated) column, not in column 7 or 8. In that case I would try this:
Code:
grep -E '^([^,]*,){5}[^,]*f' file

Or should it be an exact match in column 6?
Code:
grep -E '^([^,]*,){5}f(,|$)' file

In both cases this could be done easier using awk:
Code:
awk -F, '$6~/f/' file

and
Code:
awk -F, '$6=="f"' file

respectively


--
@paresh n doshi, you cannot really use RS here because you will get into trouble if there is more than 1 line, because it would then also match the pattern in the lower columns...

Last edited by Scrutinizer; 10-14-2013 at 07:48 AM..
# 10  
Old 10-14-2013
OP request is: Is there any way to check string is after 5th comma?
So it could be other filed than just $6, it could be $7, $8 etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

2. Shell Programming and Scripting

Make multiple lines into single quoted comma separated Linux

Hi, I want to change a file file1.txt: 1234 3456 2345 6789 3456 2333 4444 As, file2.txt in Linux: '1234','3456','2345','6789','3456','2333','4444' Could someone please help me. (Single liner sed, awk will be welcome!) (7 Replies)
Discussion started by: wiweq05
7 Replies

3. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

4. Shell Programming and Scripting

Replace a value after 13th comma in a string

Suppose b=50,0,0,40,1,0,5000,gold,0,0,0,0,32,9,2,0,10000,0,0,0,0,0,0,0,0,0,BSNL_SMS_Bundle ,null,null,null,null,null,null,null,null,null,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,null,null,0,0,405564245,0 c=11 After 13th comma, the value of 9 needs to be changed and to be filled by another... (4 Replies)
Discussion started by: karan23kohli
4 Replies

5. Shell Programming and Scripting

Awk: Remove comma at the end of the string

Hi i had String like UID: ABC345QWE678GFK345SA90, LENGTH 32 when I used awk ' FS, {print $1}' prints ABC345QWE678GFK345SA90, how can i getrid of that coma at the end of the string. Thanks in advance.. (14 Replies)
Discussion started by: Reddy482
14 Replies

6. Shell Programming and Scripting

egrep string except when preceded by underscore

having trouble with this seemingly simple taks.. :mad: Test data: we want to keep lines 2,3 & 4 -- want to exclude when ${.*schema} is preceded with an underscore; Valid {.*schema} should always be preceded spaces or be found at the beginning of a line. egrep... (5 Replies)
Discussion started by: danmauer
5 Replies

7. Shell Programming and Scripting

Delete a comma from string

Hey guys, Its a simple question though, but since I'm new to this shell scripting world ... it's kind of difficult. Say I have some string as : ListenAddress=ABCServer1,ABCServer2 I want to output the value of ListenAddress as ... ABCServer1 ABCServer2 so, basically, I want to... (6 Replies)
Discussion started by: MisterKhan
6 Replies

8. Shell Programming and Scripting

comma separated string manipulation

hi, i have a script where i am accepting a comma separated string from the user, i have to separated those strings on the basis of comma and store it in variables.. below is the script #!/bin/ksh clear echo "Enter the strings seperated by commas :- \c " read strn echo $strn... (2 Replies)
Discussion started by: saharookiedba
2 Replies

9. Shell Programming and Scripting

how to make menu of result from egrep

hi, im just starting with scripting , i have de following situation im doing a search in a data folder with egrep egrep -i "title.regu." `find . -name "*.dat"` the result is : ./20080816212245/index.dat:title Regular Expressions ./20080811212216/index.dat:title ... (5 Replies)
Discussion started by: tvrman
5 Replies

10. Shell Programming and Scripting

Comma Delimited Output w/ egrep

Hi all, I have an input file that I am pulling out certain phases using the following commands: cat /nodes.txt | egrep -e 'OSVersion|PrimaryNodeName' Currently the output looks like this: OSVersion - 5.0 PrimaryNodeName - serverA OSVersion - 5.0 PrimaryNodeName - serverB OSVersion... (2 Replies)
Discussion started by: indianadoug
2 Replies
Login or Register to Ask a Question