Visit Our UNIX and Linux User Community


By using awk, how to '(backtick)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting By using awk, how to '(backtick)?
# 1  
Old 09-17-2009
By using awk, how to '(backtick)?

Can I know how to express the '(backtick) in awk?!
By typing \' ???
# 2  
Old 09-17-2009
what do you mean by express...can you post sample file and desired output?
# 3  
Old 09-17-2009
backticks is used to evaluate commands, are you gonna execute "cat,echo" inside awk??
that's not possible.
# 4  
Old 09-17-2009
Code:
# awk 'BEGIN{printf "%c%s%c\n",39,"(backtick)",39}'
'(backtick)'

See: ASCII Character Map
# 5  
Old 09-17-2009
Actually I want to express the backticks in command and attach it to a file.
For example:
I got a list of file end at .txt. I want all of them do the same command like
awk '{print $_"\t"}' and attached it to a output .sh file.

This is the command I type:
ls *.txt | awk '{print $1, " | awk \' \{ print $_ \" \\t \" \} \' "}' > txt.sh

My desired output is when I type the command "more txt.sh "
The desired output is like this:
sample1.txt | awk '{print $_"\t"}'
sample2.txt | awk '{print $_"\t"}'
sample3.txt | awk '{print $_"\t"}'
sample4.txt | awk '{print $_"\t"}'

I got the problem when trying to show out the ' (backtick) at the txt.sh file.
I used the \' to show out the ' (backticks).
Is't because I use wrong?
Thanks a lot for your advice and suggestion.

Quote:
Originally Posted by malcomex999
what do you mean by express...can you post sample file and desired output?


---------- Post updated at 08:52 PM ---------- Previous update was at 08:51 PM ----------

Hi,
I just upload my trouble, hope you can give me some advice.
Thanks a lot ^^

Quote:
Originally Posted by ryandegreat25
backticks is used to evaluate commands, are you gonna execute "cat,echo" inside awk??
that's not possible.


---------- Post updated at 08:53 PM ---------- Previous update was at 08:52 PM ----------

Thanks for your suggestion.
Do you have any idea to help me show out the ' (backticks).
Thus I can get the desired output result.

Quote:
Originally Posted by danmero
Code:
# awk 'BEGIN{printf "%c%s%c\n",39,"(backtick)",39}'
'(backtick)'

See: ASCII Character Map
# 6  
Old 09-18-2009
Code:
$ 
$ ls -1 *.txt
sample1.txt
sample2.txt
sample3.txt
sample4.txt
$ 
$ for i in *.txt; do   echo "$i | awk '{print \$_,\"\t\"}'"; done >txt.sh
$ 
$ more txt.sh
sample1.txt | awk '{print $_,"\t"}'
sample2.txt | awk '{print $_,"\t"}'
sample3.txt | awk '{print $_,"\t"}'
sample4.txt | awk '{print $_,"\t"}'
$ 
$

BTW -

Code:
' <== Single quote character
` <== Backtick


tyler_durden
# 7  
Old 09-18-2009
Hi,
Thanks a lot.
Really thanks for your help and suggestion.
It is worked now Smilie


Quote:
Originally Posted by durden_tyler
Code:
$ 
$ ls -1 *.txt
sample1.txt
sample2.txt
sample3.txt
sample4.txt
$ 
$ for i in *.txt; do   echo "$i | awk '{print \$_,\"\t\"}'"; done >txt.sh
$ 
$ more txt.sh
sample1.txt | awk '{print $_,"\t"}'
sample2.txt | awk '{print $_,"\t"}'
sample3.txt | awk '{print $_,"\t"}'
sample4.txt | awk '{print $_,"\t"}'
$ 
$

BTW -

Code:
' <== Single quote character
` <== Backtick

tyler_durden

Previous Thread | Next Thread
Test Your Knowledge in Computers #638
Difficulty: Easy
The original iPhone had 16GB of memory.
True or False?

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

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

[Solved] Backtick and escapes

Hello all, I have a problem with a bash script. It contains an MySQL query, which when I run it 'as is', executes without a problem. When, however, I try to get it to assign its output to a variable, using the backtick, I get errors. So .. /usr/bin/mysql -N -B mydatabase -e 'SELECT... (3 Replies)
Discussion started by: davidm123SED
3 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Shell Programming and Scripting

use backtick inside awk

Hello, Can't we use backtick operator inside awk. nawk ' BEGIN { RS=""; FS="\</input\>" } { for(i=1;i<=NF;i++) { if ($i~/\"\"/) { print `grep XYZ $i`; print $i } } } ' test In the following code, I need to print $i and some... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

7. Shell Programming and Scripting

Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly? I have no problem getting the results if the command is properly executed. Ex. my @result = `dir`; foreach my $line (@result) { print "Result = $line";... (2 Replies)
Discussion started by: kooshi
2 Replies

8. Shell Programming and Scripting

Perl: combine Backtick & system() I/O operation?

Hi - Within perl I want to execute a system command. I want to re-direct all the output from the command to a file (@result = `$cmd`;), but I ALSO want the results to be displayed on the screen (system("$cmd"); The reason is this - if the command completes, I want to process the output. If the... (6 Replies)
Discussion started by: jeffw_00
6 Replies

9. Shell Programming and Scripting

Awk problem: How to express the backtick(')

For example: I got a list of file end at .txt. I want all of them do the same command like grep '^@' and attached it to a output .sh file. This is the command I type: ls *.txt | awk '{print "grep \' \^\@\' ",$1}' > txt.sh My desired output is when I type the command "more txt.sh " The... (4 Replies)
Discussion started by: patrick87
4 Replies

10. UNIX for Advanced & Expert Users

Help with GNU screen: Backtick and Caption.

I'm trying to get GNU screen to show the output of "uptime" for the host being accessed in the current window, but unfortunately, no matter what window I go in, it shows the uptime for the host I originally launched screen in ("adminhost"). Does anyone know how to get this to update from the... (0 Replies)
Discussion started by: akbar
0 Replies

Featured Tech Videos