Pass column number as variable to awk and compare with a string.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass column number as variable to awk and compare with a string.
# 8  
Old 11-12-2014
Girish19,
important! You'll want to use:
Quote:
Originally Posted by RudiC
Code:
awk -v COL=2 '$COL ~ "vinay" {print $0}' test.txt

RudiC,
spot-on! I have got it!
Both proposals failed when I added a fourth record with "vinay" in the third field Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

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

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

Help with compare two column and print out column with smallest number

Input file : 5 20 500 2 20 41 41 0 23 1 Desired output : 5 2 20 0 1 By comparing column 1 and 2 in each line, I hope can print out the column with smallest number. I did try the following code, but it don't look good :( (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Red Hat

pass a variable line number to sed

num=10 sed -n '$num p' test.txt sed -n '10 p' test.txt works however i am putting the sed command in a loop and the line number is not static Can someone please help me how to achive this. (1 Reply)
Discussion started by: figure20012
1 Replies

6. Shell Programming and Scripting

awk arrays - compare value in second column to variable

Hello, I am trying to redirect files to a directory by using a config file. The config files is as such: xxxxxx,ID,PathToDirectory xxxxxx,ID2,PathToDirectory2 and so on... I have a variable that should match one of these IDs. I want to load this config file into an awk array, and... (2 Replies)
Discussion started by: jrfiol
2 Replies

7. Solaris

awk - Print variable number of colums from a starting column

Hi guys, I usualy am able to google awk stuff but I can't find it so far and there are so many awking gurus here that I will give it a shot. I want to print $1;$3;"$5 up to the $NF". In other words, I can have 1000 colums, but need to have $5 up to the end. I started with the idea of... (2 Replies)
Discussion started by: plmachiavel
2 Replies

8. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

9. Shell Programming and Scripting

awk conditional expression to compare field number and variable value

Hi, I'm trying to compare the value in a field to the value in a variable using awk. This works: awk '$7 == "101"'but this is what I want (and it doesn't work): value=101 awk '$7 == "$value"' Any help or insight on this would be great. Thanks in advance. (1 Reply)
Discussion started by: goodbenito
1 Replies

10. Shell Programming and Scripting

need help with counting of files then pass number to variable

hi all, i'm trying to pass a count of files to a variable thru these set of codes: sh_count=$(ls -1 fnd_upload_LV*.* |wc -l) problem is if no files matches that, it will give an error "ls: fnd_upload_LV*.*: No such file or directory". how do i avoid having the shell script show that... (2 Replies)
Discussion started by: adshocker
2 Replies
Login or Register to Ask a Question
ALSEARCH(1)						User Contributed Perl Documentation					       ALSEARCH(1)

NAME
alsearch - Search the AudioLink database for music SYNOPSIS
alsearch [OPTION]... search_option... --td=/some/path/to/create/links/ alsearch [OPTION]... search_option... -s DESCRIPTION
You can use this script to search for songs in the AudioLink database. You can specify one or several options for the artist, composer, lyricist, album, etc., as the search criteria. You can specify several search_option options to search for particular music files. See the section on "search options" for the list of options. The search is not case sensitive. alsearch looks for strings as well as sub-strings in the fields being searched. See the "examples" section for more information. Specifying the --td (target directory) option is mandatory for creating links to the actual files. This directory will contain the symbolic links to the actual audio files. The directory will be created if it doesn't exist. Creating symbolic links to the actual files is analogous to creating playlists in audio-playing software. Symbolic links are actually just point to the actual files on the hard disk. This way of creating and storing playlists is very useful in several ways, some of which are: 1. Compatible across various audio players Since the "playlists" are actually files represented on your hard disk, you can add whole directories generated by the alsearch program in the playlist of your audio software. If you switch to another music player for whatever reason, you still have your playlists. You don't have to bother about compatibility between the playlist formats of the two players. 2. Can be seen and operated upon in a file browser As the symbolic links are present on a file-system, your playlist collection can be viewed by using normal file operations in the shell or using a GUI-based file browsing program. If the file browsing program is supports file traversals and symlinks, it'll show you the information of the actual song. OPTIONS
--help Brief usage information --host=xxx Connects to the MySQL server on the target host. Default is localhost. --pass=xxx Password for the database -s, --na Just displays the search results, doesn't create links (simulation mode) --td=xxx Target-directory in which to create links --user=xxx Username for the database -v, --verbose Displays some extra information. Useful for spotting errors and sending debug information. SEARCH OPTIONS
--album=xxx Search in the "album" field --artist=xxx Search in the artist/band/performers fields. You can give this option multiple times, for example: "alsearch --artist=kishore --artist=asha --td=/songs/asha_kishore" --comment=xxx Search in the "comment" field -c, --composer=xxx Search in the "composer" field --genre=xxx Search in the "genre" field -l, --lyricist=xxx Search in the "lyricist" field --title=xxx Search in the "title" field EXAMPLES
The options that take arguments can be specified in two ways: "alsearch --artist="kishore kumar" --td=/songs/kishore" "alsearch --artist "kishore kumar" --td /songs/kishore" That is, the option and the argument can be separated with a ' ' (space) or an '=' (equal) sign. In case you want to search for a string that has spaces, enclose the string in " ". "alsearch --artist=kishore --composer=burman --lyricist=bakshi" Will search for songs sung by *Kishore*, composed by *Burman* and written by *Bakshi*. Any name in the composer field which have "burman" in them will be matched. This means, it'll find songs composed by RD Burman, SD Burman, etc. This is true for all search fields. SEE ALSO
L<audiolink(1)>, L<alfilldb(1)> The current version of this man page is available on the AudioLink website at <http://audiolink.sourceforge.net/>. BUGS
Report bugs related to the AudioLink software or the man pages to the audiolink-devel mailing list <audiolink-devel@lists.sourceforge.net>. AUTHOR
This manual page is written and maintained by Amit Shah <amitshah@gmx.net> COPYRIGHT
The AudioLink package is Copyright (C) 2003, Amit Shah <amitshah@gmx.net>. All the programs and the documentation that come as part of AudioLink are licensed by the GNU General Public License v2 (GPLv2). perl v5.14.2 2003-12-06 ALSEARCH(1)