Awk: single quote match in If


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: single quote match in If
# 1  
Old 01-05-2018
Awk: single quote match in If

Hello,

I'd like to print line if column 5th doesn't match with exm. But to reach there I have to make sure I match single quote.
I'm struggling to match that.

I've input file like:
Code:
Warning: Variants 'exm480340' and '5:137534453:G:C' have the same position.
Warning: Variants 'exm480345' and '5:137536897:C:G' have the same position.
Warning: Variants 'exm2274094' and '5:137548976:G:C' have the same position.
Warning: Variants 'exm480367' and '5:137548988:G:A' have the same position.
Warning: Variants 'exm480373' and '5:137588691:G:A' have the same position.
Warning: Variants 'exm480383' and '5:137589456:G:A' have the same position.
Warning: Variants 'exm480395' and '5:137593337:G:A' have the same position.
Warning: Variants 'exm480405' and '5:137593620:A:G' have the same position.
Warning: Variants 'exm2087676' and '5:137599964:C:T' have the same position.
Warning: Variants 'exm480435' and '5:137621421:C:T' have the same position.

Warning: Variants 'exm2256415' and 'exm2067772' have the same position.

Code:

Code:
grep " have the same position." input.log | awk ' { if( $5 ~ /^\'/ ){print $0} }  '

Error:
Code:
-bash: syntax error near unexpected token `)'


I tried with "'" too, but it failed.
How do I get around this error?


Moderator's Comments:
Mod Comment Please use CODE (not QUOTE) tags for data as well as required by forum rules!


Edit: Sure, I'll use CODE for data.
I've added line for which I'm writing awk line.

Last edited by genome; 01-05-2018 at 12:37 PM.. Reason: Changed CODE tags.
# 2  
Old 01-05-2018
Not clear. How should '5:137534453:G:C' "match with exm"?

For single quotes, you could e.g. define a variable outside the awk script.
# 3  
Old 01-05-2018
Hi Rudic,

Sorry, I've edited my post. Missed the case I'm intending to use awk and if.
# 4  
Old 01-05-2018
Try
Code:
awk -vSQ="'" '
/have the same position./ && 
$5 ~ "^" SQ
' file

# 5  
Old 01-05-2018
Code:
grep " have the same position." input.log | awk ' { if( $5 ~ /^\x027/ ){print $0} }  '

# 6  
Old 01-05-2018
Quote:
Originally Posted by rdrtx1
Code:
grep " have the same position." input.log | awk ' { if( $5 ~ /^\x027/ ){print $0} }  '

Thanks.
It frustrates me how simple things don't work on awk/bash.

Code:
 grep " have the same position." input.log | awk ' { if( $5 ~ /^\x027exm/ ){print $0} }  '

I added exm to \x027
If I added "exm" again code fails.
# 7  
Old 01-05-2018
Another slight variation
Code:
awk -v re="^'" '/ have the same position\./ && $5~re' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

2. Shell Programming and Scripting

How to match character with single quote?

I need to check whether first character of variable is single quote. I tried the below constructions but they are all not working (always return true) if (test `echo "$REGEXP" |cut -c1` != "'"); then echo "TRUE"; fi if (test `echo "$REGEXP" |cut -c1` != '\''); then echo "TRUE"; fi if (test... (5 Replies)
Discussion started by: urello
5 Replies

3. Shell Programming and Scripting

How to use awk in inserting single quote

Hi Guys, Please someone help me to insert these numbers (enclosed with single quotes) to a statement using awk command. I'm having hard time of putting single quotes on these numbers. input file: 10214 68441 07205 80731 92234 55432 DESIRED OUTPUT: My ID Number='10214';... (1 Reply)
Discussion started by: pinpe
1 Replies

4. Shell Programming and Scripting

How do you print a single quote character in AWK

How do you print out a single quote character in AWK? Using the escape character does not seem to work. {printf "%1$s %2$s%3$s%2$s\n" , "INCLUDE", " \' ", "THIS" } does not work. Any suggestions? (6 Replies)
Discussion started by: cold_Que
6 Replies

5. Shell Programming and Scripting

awk print: howto single quote not interpreted!?

cat a | awk -F";" '{print "update db set column=' "$2" ' where column1=\""$1"\";"}' > ip-add.sql Hi! I'm a new user! i need to use single quote in the double quotes print string The apex between che "$2" should not be interpreted, but....how?! I'm trying to use \ but don't work correctly! ... (4 Replies)
Discussion started by: Re DeL SiLeNziO
4 Replies

6. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

7. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

8. Shell Programming and Scripting

want to print single quote using awk

i want to print ' symbol using awk i tried: awk '{print " ' "}' awk '{print "\' "}' both not work please help me. (2 Replies)
Discussion started by: RahulJoshi
2 Replies

9. UNIX for Dummies Questions & Answers

how to print single quote in awk

Hi all, It is a very stupid problem but I am not able to find a solution to it. I am using awk to get a column from a file and I want to get the output field in between single quotes. For example, Input.txt 123 abc 321 ddff 433 dfg ........ I want output file to be as ... (6 Replies)
Discussion started by: gauravgoel
6 Replies

10. Shell Programming and Scripting

AWK handling of single quote

Hi, Can someone let me know how I can acheive the following. I have ~ delimited file and I need to convert into something like SQL insert statements. SrcFile : 1~sjdsdj~asasas~ 2~aaaaa~qwqwqwq~qwq ..... I tried AWK -F"~" '{print "INSERT INTO XX VALUES("$1 " ,\' "$2" \' , \' "$3 }'... (3 Replies)
Discussion started by: braindrain
3 Replies
Login or Register to Ask a Question