Printing apostrophes by using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing apostrophes by using awk
# 1  
Old 10-26-2015
Printing apostrophes by using awk

Hello All,

I would like to ask your kind help regarding the following query:

I have this line:
Code:
awk '$2>5 {print "File:  "$1,$2}'

I have got this output:
Code:
File: zzzds 76
File: fd9ffh 58
File: gfh0dg 107
....

Could you please help me how to modify my line to get these outputs with apostrophs?

Code:
File: 'zzzds 76'
File: 'fd9ffh 58'
File: 'gfh0dg 107'
...

Thank you in advance for your help.

Padavan


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 10-26-2015 at 09:37 AM.. Reason: code tags
# 2  
Old 10-26-2015
Hello Padavan,

Please use code tags as per forum rules for commands/codes/Inputs used in your posts as per forum rules. You could go through the rules in following link too.
https://www.unix.com/misc.php?do=cfrules

Now on your question, could you please use following and let me know if this helps you.
Code:
awk -vs1="'" '$2>5 {print "File: " OFS s1 $1,$2 s1}' Input_file

Also on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk .

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-26-2015
\047 also works, that is backslash zero four seven, awk's octal notation for a single quote.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-26-2015
If you have a really really old awk:

Code:
awk '
BEGIN {
a="'"'"'"
}
{
print a
}'

That's doublequote singlequote doublequote singlequote doublequote singlequote doublequote

Has do do with shell escaping. Should work everywhere...
This User Gave Thanks to cjcox For This Post:
# 5  
Old 10-26-2015
With colors you can easily see the the escaped ' outside the 'strings':
Code:
awk '
BEGIN { tck="'"'"'" }
{ print tck "hello world" tck }'

I usually prefer the '\'' escape:
Code:
awk '
BEGIN { tck="'\''" }
{ print tck "hello world" tck }'

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 10-27-2015
Hello All,

Thank you very much for your kind help. Much appreaciated.

I apologize if I caused any inconveniences.

With Best Regards,

Padavan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problems with deleting punctuation and apostrophes

Dear All, I have a file which I want to get the list of frequency of each word, ignoring list of stop words and now I have problems which punctuations and " 's ". what I am doing is: sed 's///g' file01.txt > file01-clear.txt cat file01-clear.txt | tr "" ""| tr ' ' '\012' |sort |uniq -c... (3 Replies)
Discussion started by: A-V
3 Replies

2. Shell Programming and Scripting

Printing using awk

Hi I am relatively new to awk so i am getting confused a lot I am in need of help ... I am trying to append coloumns to the end of line using AWK I tried using this command awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 Replies

3. Shell Programming and Scripting

Help with awk: printing variables

awk is only printing out the variables on the first AK2, how do I get it to print out the variables for every occurrence of AK2? grep -l "^ST.997" *.replaced|sort -n|uniq>FILELIST while read file do let "count = $count+1" <$file awk 'BEGIN { FS="" ... (0 Replies)
Discussion started by: verge
0 Replies

4. Programming

Regex to pull out all words in apostrophes in a string

Hi, I have string like this: CHECK (VALUE::text = ANY (ARRAY)) and I am trying to get out the words in apostrophes ('). In this case"ACTIVE INACTIVE DELETE" Also the array may consist of one or more words (in given example 3). Also instead of word it can be only one LETTER. And... (4 Replies)
Discussion started by: neptun79
4 Replies

5. Shell Programming and Scripting

Awk selective printing

Hi, i need help to print number from different field INPUT: Student1 10 20 Student2 30 40 Student3 50 60 Student4 70 80 Desired Output: 1 20-30 2 40-50 3 60-70 Thank you! (5 Replies)
Discussion started by: saint2006
5 Replies

6. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

7. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

8. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in quotes.like "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

9. Shell Programming and Scripting

How to include a variable between apostrophes within a command

Hi. I'm trying to find some words within my directory and created a text file containing them which is read by my shell script: #!/bin/bash var=`cat words.txt` for i in $var; do echo $i find -type f -print0 | xargs -r0 grep -F '$i' done But it searches "$i" (dollar sign... (2 Replies)
Discussion started by: guarriman
2 Replies

10. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies
Login or Register to Ask a Question