awk if one liner syntax for equating with a string variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk if one liner syntax for equating with a string variable
# 1  
Old 10-03-2012
awk if one liner syntax for equating with a string variable

I would like to have help with syntax for using a string varaibles inside if and else in a awk one liner.
Eg. I would like to say, list all the filenames that have been modified in a particular month(present in a string variable) or list all the filenames whose owner is $owns and owner group is $group in current directory by using awk one liner...
I tried
Quote:
${month_value} , $month_value , "${month_value}"
with '==' but its either taken literally or gives error.. I am using:
Code:
ls -ltr | awk '{if ($6 == "${month_value}"){print $9 }' > filestobeprocessed.txt

# 2  
Old 10-03-2012
see this post
# 3  
Old 10-03-2012
Code:
ls -ltr | awk -v m="$month_value" '$6==m{print $9}' > filestobeprocessed.txt

# 4  
Old 10-03-2012
try
Code:
ls -ltr | awk '$6 == '$month_value' {print $9 }' > filestobeprocessed.tx

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for string in column using variable: awk

I'm interested to match column pattern through awk using an external variable for data: -9 1:751343:T:A -9 0 T A 0.726 -5.408837e-03 9.576603e-03 7.967536e-01 5.722312e-01 -9 1:751756:T:C -9 0 T C 0.727 -5.360458e-03 9.579447e-03 7.966977e-01 5.757858e-01... (7 Replies)
Discussion started by: genome
7 Replies

2. Shell Programming and Scripting

Concat String with variable after a 'grep' and awk

Here is the structure of my file: MyFile.txt g-4.n.g.fr 10.147.243.63 g-4.n.g.fr-w1 Here is my sript: test.sh #! /bin/sh ip=10.147.243.63 worker=$(grep -e $ip $1 | awk '{ print $3; }') echo "" echo $worker echo "" echo $worker echo "" echo "$worker.v.1" echo... (7 Replies)
Discussion started by: chercheur111
7 Replies

3. UNIX for Advanced & Expert Users

Pass variable to awk command search string

I must have forgot how to do this, but, I am attempting to enter a variable into an awk / gawk search pattern. I am getting a value from user input to place in a specific section of a 132 character string. my default command is .... gawk --re-interval '/^(.{3}P .{4}CYA.{8}1)/' ... (3 Replies)
Discussion started by: sdeevers
3 Replies

4. Shell Programming and Scripting

Cleaner way to use shell variable in awk /X/,/Y/ syntax?

$ cat data Do NOT print me START_MARKER Print Me END_MARKER Do NOT print me $ cat awk.sh start=START_MARKER end=END_MARKER echo; echo Is this ugly syntax the only way? awk '/'"$start"'/,/'"$end"'/ { print }' data echo; echo Is there some modification of this that would work? awk... (2 Replies)
Discussion started by: hanson44
2 Replies

5. 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

6. Shell Programming and Scripting

awk syntax(partial) in variable

if a variable has part of awk syntax stored in it. for eg: x=if($1>100) can we substitute this variable in an awk statement. based on above requirement can we execute something like: awk '{x print $1}' infile (5 Replies)
Discussion started by: 47shailesh
5 Replies

7. Shell Programming and Scripting

Help with awk and accessing variable values within the syntax

I'm writing a bash script, and I am having trouble with this line: awk '{print "url = \"http://www.example.com/directory/$type/"$1"\""}' input.file > output.file Within the URL being printed, I wish the value of the variable "$type" to be printed, after being read from user input from the... (2 Replies)
Discussion started by: meridionaljet
2 Replies

8. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

9. Shell Programming and Scripting

awk: change string variable

Hi. How to change string variable in awk? for example, I parse with awk script text file named some_name_with_extension.txt I want to print only some_name in my script .... varCompName = FILENAME print varCompName How to put not all symbols from FILENAME to variable? thank you This... (4 Replies)
Discussion started by: cintlt
4 Replies

10. Shell Programming and Scripting

Is there any one liner method to mirror string ?

for example I have 123 and I will like it to be 321 thanks (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question