Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How to print backslash in shell script using awk?

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
wxuyec's Unix or Linux Image
wxuyec wxuyec is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 14 February 2013, 12:22 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
How to print backslash in shell script using awk?

I found that

Code:
echo "aaa" | awk '{print ",\\";}'

works, and it will give "\".

but

Code:
ddd=`echo "aaa" | awk '{print ",\\";}'`; echo $ddd

will not work.
Could anyone tell me why? thank you.

Last edited by Scrutinizer; 01-30-2013 at 04:15 PM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 16 December 2017, 5:11 PM EST
Location: Galactic Empire
Posts: 3,613
Thanks: 254
Thanked 1,317 Times in 1,234 Posts

Code:
ddd=$( echo "aaa" | awk '{print ",\\";}' )
echo $ddd

Sponsored Links
    #3  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
wxuyec's Unix or Linux Image
wxuyec wxuyec is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 14 February 2013, 12:22 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
it works, Thank you.
    #4  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 213 Times in 203 Posts
You can use BEGIN to make awk work without no input

Code:
ddd=$(awk 'BEGIN {print ",\\";}' )

Sponsored Links
    #5  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 16 December 2017, 11:08 AM EST
Location: Aachen, Germany
Posts: 11,815
Thanks: 341
Thanked 3,659 Times in 3,357 Posts

Code:
$ ddd=",\\"; echo $ddd
,\

UUOA?
Sponsored Links
    #6  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 16 December 2017, 12:59 PM EST
Location: Amsterdam
Posts: 11,660
Thanks: 520
Thanked 3,386 Times in 2,985 Posts

Code:
ddd=,\\

UUOQ&A Linux
Sponsored Links
    #7  
Old Unix and Linux 01-30-2013   -   Original Discussion by wxuyec
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 16 December 2017, 5:11 PM EST
Location: Galactic Empire
Posts: 3,613
Thanks: 254
Thanked 1,317 Times in 1,234 Posts
OP never gave a complete picture of what he was trying to achieve. Thread title is just: "How to print backslash in shell script using awk?"

So I'm not sure if it was UUOQ & UUOA
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing backslash character to awk variable Mudshark Shell Programming and Scripting 5 11-18-2012 12:38 PM
awk/shell script to print each line to a file saint2006 Shell Programming and Scripting 3 01-06-2010 11:26 AM
shell script(Preferably awk or sed) to print selected number of columns from each row ks_reddy Shell Programming and Scripting 3 08-25-2009 08:39 AM
Sed and awk backslash characters potro Shell Programming and Scripting 7 05-19-2008 09:34 AM
Shell Script -- problem reading backslash(\)!! rossi143 Shell Programming and Scripting 2 04-04-2007 03:52 AM



All times are GMT -4. The time now is 06:35 PM.