output with ' in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers output with ' in awk
# 1  
Old 07-03-2011
output with ' in awk

If I want to use awk to get and output like:

x ' y

How do I do it?

This is what I tried:

Code:
 1409  awk '{print "x ' y"}' all
 1410  awk '{print "x \' y"}' all
 1411  awk '{print "x \\' y"}' all
 1412  awk '{print "x /' y"}' all
 1413  awk '{print "x //' y"}' all

but nothing worked! Smilie
# 2  
Old 07-03-2011
Code:
awk "{print \"x ' y\"}" all

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-03-2011
Hi.

To eliminate (some) backslashes and make the single-quote more "visible" in the script:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate variable setting for single-quote character, awk

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C awk

pl " Results:"
awk -v sinquo="'" '
BEGIN	{ print " Single quote is ( " sinquo " )" ; exit }
'

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
GNU bash 3.2.39
GNU Awk 3.1.5

-----
 Results:
 Single quote is ( ' )

Best wishes ... cheers, drl
# 4  
Old 07-04-2011
Quote:
Originally Posted by bartus11
Code:
awk "{print \"x ' y\"}" all


What is I want an out put like this:

hi ' (values o column 1 in the file all)

This is what I tried:

Code:
awk "{print \"hi ' \"$1\" \"}" all > testing.txt

And

Code:
awk "{print \"hi ' "$1" \"}" all > testing.txt

Code:
awk "{print \"hi ' \"$1}" all > testing.txt

or
In all cases this is what I get (the actual data column is missing)

Code:
 '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '
hi '


Last edited by cosmologist; 07-04-2011 at 02:20 AM..
# 5  
Old 07-04-2011
Try:
Code:
awk '{print "hi \047 " $1}'  all > testing.txt

You can also use a variable for the quote like:
Code:
awk -v q="'" '{print "Hi " q " " $1}'  all > testing.txt

This User Gave Thanks to Franklin52 For This Post:
# 6  
Old 07-04-2011
I am trying to use that to get columns from 2 different files:


Code:
awk '{print "awk \047FNR==NR {a[FNR]=$1"  "$2;next} {print a[FNR],"  "$1"  "$2"  "$3"  "$4"  "$5"  "$6"  "$7"  "$8"  "$9"  "$10"  "$11"  "$12}\047  cdobj3043.norm "$1" > real_"$1}' all > testing

But in the output I don't get spaces between the column numbers:

Code:
awk 'FNR==NR {a[FNR]=$1$2;next} {print a[FNR],$1$2$3$4$5$6$7$8$9$10$11$12}'  cdobj3043.norm model_10000.tab > real_model_10000.tab
awk 'FNR==NR {a[FNR]=$1$2;next} {print a[FNR],$1$2$3$4$5$6$7$8$9$10$11$12}'  cdobj3043.norm model_10500.tab > real_model_10500.tab
awk 'FNR==NR {a[FNR]=$1$2;next} {print a[FNR],$1$2$3$4$5$6$7$8$9$10$11$12}'  cdobj3043.norm model_11000.tab > real_model_11000.tab
awk 'FNR==NR {a[FNR]=$1$2;next} {print a[FNR],$1$2$3$4$5$6$7$8$9$10$11$12}'  cdobj3043.norm model_11500.tab > real_model_11500.tab

# 7  
Old 07-04-2011
Code:
awk '{print "x '\'' y"}' infile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

2. Shell Programming and Scripting

awk output

hello all input file AAA: XXX1 CCC: DD SS SSS: SSS1 BBBB: ASAS ZZZ: ZZZZZ1 XXX: XXXXXXXXXXXXXXX1 PPPP: PPPPPP1 RRRR: 111111111 ZZZ: ZZZZZ2 XXX: XXXXXXXXXXXXXXX2 PPPP: PPPPPP2 RRRR: 222222222 ZZZ: ZZZZZ3 XXX: XXXXXXXXXXXXXXX3 PPPP: PPPPPP3 RRRR: 33:33:33:33:33 (2 Replies)
Discussion started by: vikus
2 Replies

3. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

help on awk---- need to assign the output of awk to a variable

hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb. i am doin this script, but it is throwing error.... #!/bin/ksh cd . | du -s | size = awk '{print $1}' if size >= 112000 then echo size high fi ERROR : (4 Replies)
Discussion started by: Nithz
4 Replies

6. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

9. Shell Programming and Scripting

Same awk gives different output:

nawk -F"|" '{for (i=1;i<=NF;i++) {gsub("^*", "",$i);gsub("*$", "",$i)}}1' OFS="|" file | wc -l 1000 nawk -F"|" '{for (i=1;i<=NF;i++) {gsub("^*", "",$i);gsub("*$", "",$i);print $0}}' OFS="|" file | wc -l 22000 The above awk command are same but with different printing... (1 Reply)
Discussion started by: pinnacle
1 Replies

10. Shell Programming and Scripting

awk output

could any one tell me why the following code is working in infinite loop every time it is asking for no. even though it does not have for loop #!/bin/awk -f BEGIN { print "type a number"; } { print "The square of ", $1, " is ", $1*$1; print "type another number"; } END { ... (3 Replies)
Discussion started by: useless79
3 Replies
Login or Register to Ask a Question