I have already described in one of the earlier posts on how to print string within single quote in Awk print statement. Here is how we can print strings without "double quotes" in Awk.
Here are some of the alternatives:
$ cat file.txt
6289693505455 Plan_DAIL_30D_AA
6289693505475 Plan_DAIL_30D_AA
6289693505462 Plan_DAIL_30D_AB
Output required:
Plan_DAIL_30D_AA "6289693505455" Plan_DAIL_30D_AA "6289693505475" Plan_DAIL_30D_AB "6289693505462"i.e. Print the first field of the file within "double quotes".
Here are some of the alternatives:
$ awk '{print $2,$1}' file.txt Plan_DAIL_30D_AA 6289693505455 Plan_DAIL_30D_AA 6289693505475 Plan_DAIL_30D_AB 6289693505462 $ awk '{print $2,"\""$1"\""}' file.txt Plan_DAIL_30D_AA "6289693505455" Plan_DAIL_30D_AA "6289693505475" Plan_DAIL_30D_AB "6289693505462" #Assigning the quotes sequence to a variable x $ awk -v x="\"" '{print $2,x$1x}' file.txt Plan_DAIL_30D_AA "6289693505455" Plan_DAIL_30D_AA "6289693505475" Plan_DAIL_30D_AB "6289693505462" #Using octal code of double quotes $ awk '{print $2,"\042"$1"\042"}' file.txt Plan_DAIL_30D_AA "6289693505455" Plan_DAIL_30D_AA "6289693505475" Plan_DAIL_30D_AB "6289693505462" #Using ASCII code of double quotes $ awk '{print $2,"\x22"$1"\x22"}' file.txt Plan_DAIL_30D_AA "6289693505455" Plan_DAIL_30D_AA "6289693505475" Plan_DAIL_30D_AB "6289693505462"Related posts: - Accessing external variable in Awk and Sed
3 comments:
very nice post for bash codes you can also visit http://cshonours.blogspot.in/
thank you
while read -r f1 f2; do; printf '%s "%s"\n' "$f2" "$f1"; done < file.txt
if='file.txt'
< $if perl -lane '$,=$"; print map { "[$_]" } @F' |
dc -e "
[q]sq #quit caller
[32a]sS #stores a space
[34a]sQ #stores a double quote
# print format
[n lSxn lQxn n lQxp]sp
# while loop for reading in lines
[? z 0 =q lpx c l?x]s?
# action
l?x
"
Post a Comment