Why do we use a colon (:) in grep?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Why do we use a colon (:) in grep?
# 1  
Old 01-24-2012
Why do we use a colon (:) in grep?

Can some one please explain why do we use colon in a grep statement .
for eg:
Code:
ORACLE_SID=$(grep :$(echo $JOBNAME |cut -c1-3): ${SWENV_TAB}|awk -F: '{print $1}')


Thanks in advance
Sri

Last edited by Franklin52; 01-24-2012 at 11:14 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-24-2012
Seems that's what the script wants to find in ${SWENV_TAB}.. Possibly the output looks like

Code:
SID:PID:possibly more stuff

From which the awk statement will grab $1, which is the SID. In other words: it's a literal ':' to be found in the file.
# 3  
Old 01-24-2012
Because we're looking for the first field of a record that contains a value which consists of the first three characters of the variable JOBNAME bounded by colons in the file named in the SWENV_TAB variable.

Or to rephrase it there are 2 parameters to the grep statement the first can be written as ":$(echo $JOBNAME | cut -c1-3):" the $(...) construct causes the contents to be evaluated
# 4  
Old 01-24-2012
Why do we use a colon (:) in grep?

Thanks a ton neutronscott and Skrynesaver
Asking this out of curiosity ..

i) what will happen to the same grep statement if I remove the colon or


ii)what will happen if there is a different delimiter ,lets say (,) the will
Code:
ORACLE_SID=$(grep ,$(echo $JOBNAME |cut -c1-3),${SWENV_TAB}|awk -F: '{print $1}')

give me the same output..

Thanks
Sri
Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 01-24-2012 at 05:27 AM..
# 5  
Old 01-24-2012
so long as the delimiter has no meaning to the shell, then yes any delimiter can be used, as "," has no special meaning to the shell in this context, it should work.
# 6  
Old 01-24-2012
IOW, , or : has no special meaning to grep. They added : to the pattern because they were actually looking for it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print string after colon?

Hi How do I print character after colon":" below is input file BUC1 : 33157147, BUC1 COUNT : 478455,BUC1 : 9930334.18 BUC2 : 1203100,BUC2 COUNT : 318678,BUC2 GIVEN : 3493491.59 BUC3 : 234567.99 expected output 33157147 478455 9930334.18 12031002 318678 3493491.59 234567.99 (10 Replies)
Discussion started by: scriptor
10 Replies

2. UNIX for Dummies Questions & Answers

awk colon separated items

Hi, I need to filter my data based on items in column 23. Column 1 until column 23 are tab separated. This is how column 23 looks like: PRIMARY=<0/1:504:499,5:.:.:.:0.01:1:15:.> I want to extract lines if items 7 (separated by : ) in column 23 are more than 0.25 . In example above , item... (2 Replies)
Discussion started by: janshamsani
2 Replies

3. Shell Programming and Scripting

Print after colon

I have entries like below in a file 11.22.33.44:80 22.33.44.55:81 :::587 :::465 What I need is to take out the part after colon ( : ) Output should be as follows. 80 81 587 465 I used cut -d: -f 2 but its not working as dedired. (2 Replies)
Discussion started by: anil510
2 Replies

4. Shell Programming and Scripting

Use of colon

There was a sample code on forum I found sometime back: $ f() { local foo=; : ${foo=unset}; declare -p foo; }; f declare -- foo="" $ f() { local foo; : ${foo=unset}; declare -p foo; }; f declare -- foo="unset" Can someone explain why was colon (:) is being used here. Whats its use? (4 Replies)
Discussion started by: Rameshck
4 Replies

5. Shell Programming and Scripting

How to replace colon in HH:MI:SS to hypen?

I have a file that contains timestamp in some of the rows in the file and the field separator is colon and some of the rows have numerical values, timestamp and characters with colon as the field separator We are looking to change colon in HH:MI:SS for the timestamp to hyphen “-“ leaving the field... (1 Reply)
Discussion started by: cumeh1624
1 Replies

6. Shell Programming and Scripting

Bash, remove numbers after colon

Hello All, I was wondering if someone might know how to do this. I have a word list that is format like the example below. I need to take away the :number after that... is there some kind of command I could use to remove them? 123456:5562 password:1507 123456789:989 qwerty:877... (7 Replies)
Discussion started by: 3therk1ll
7 Replies

7. Shell Programming and Scripting

Sort numbers which has colon (:) in between

Although i tried multiple option i couldn't find a way to get the rigt ouput. Say i have the following data cat file.txt C request C response C request C response The output should look like (9 Replies)
Discussion started by: varu0612
9 Replies

8. Shell Programming and Scripting

Script required to put colon

Hi Expert, I need help on script to put colon between two characters. From this line 60060160B18414009C557D9DE02CDF11 to this 60:06:01:60:B1:84:14:00:9C:55:7D:9D:E0:2C:DF:11 Any way to make it on script. (2 Replies)
Discussion started by: ranjancom2000
2 Replies

9. Shell Programming and Scripting

Remove char after Colon

Hi guys, This is my input 2735:<7001> 34 789 701 2 2774:<7001> 34 789 701 2 How to delete characters after colon : Including colon : too ? My output should... (3 Replies)
Discussion started by: gowrishankar05
3 Replies

10. Solaris

how to delimit a colon

I want to know how to delimit a colon in a file name while scp ing from one host to other host. I used forward slash(\) but that is not working. (1 Reply)
Discussion started by: rogerben
1 Replies
Login or Register to Ask a Question