Skip to main content

All Questions

Tagged with
0 votes
2 answers
232 views

How to expand variable within a single-quoted argument?

I am trying to perform the following without luck: SORT_BY='-k3,3r -k2,2 -k1,1r' awk 'NR<4{print $0;next}{print $0 | sort '"${SORT_BY}"' -t"~"}' I have tried with all sorts of quotes, unquote, ...
Whimusical's user avatar
0 votes
2 answers
4k views

using awk to print backslash

I am having trouble printing (or searching) for sequences containing backslashes when using awk For example - echo "test\test" | awk '{ gsub(/\\\\t/, "\\\\&"); print }' will give the result: ...
tomer's user avatar
  • 1
4 votes
1 answer
788 views

Prevent awk from removing "\" (backslashes) in variable

I have this line of code for the shell: ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" '{print "File Name: "$0"\n"here"\n"source}' Unfortunately it outputs: File Name: Data 00053....
Ken Ingram's user avatar
1 vote
3 answers
5k views

echo $ along with variable

Im trying to do print last directory like below #!/bin/bash dirc="/a/b/" i=3 `echo "$dirc" | awk -F / '{ print ""$"i"}'` which should print 'b', which is not happening.
Srikanth Yadake's user avatar
0 votes
1 answer
3k views

Escaping backslash with awk in OSX

I'm trying to match \N in a field of a csv file. I've tried awk -F "|" '($12=="\N") {print}' ./filename.csv awk -F "|" '($12==\N) {print}' ./filename.csv awk -F "|" '($12==\\N) {print}' ./filename....
zzzbbx's user avatar
  • 221
2 votes
1 answer
1k views

awk pattern with variable in a bash script

I have problem with command awk in bash I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line? awk -F" " "/$PWD/ {print $1,$3}" file.txt
applenic's user avatar
  • 601
2 votes
1 answer
3k views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
SpruceTips's user avatar
2 votes
2 answers
4k views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
Anil's user avatar
  • 21