Sponsored Content
Top Forums Shell Programming and Scripting Using awk to read a specific line and a specific field on that line. Post 302543310 by agama on Saturday 30th of July 2011 10:45:29 PM
Old 07-30-2011
I'd use awk, but that's a matter of personal preference. This is the simplest form which will find your search string anywhere on the record:

Code:
awk -v what=$search '
    { if( index(  $1, what ) )   # record contains string
        print $1, $2;                # print any part of the record desired
    }
'

If you need to search for a regular expression, then you could use match() instead of index.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to append a character to the last but one field on a specific line?

Hi Guys, I have a file like this: aaa b c d e f fsss g h i k l qqq r t h n I want: aaa b c d e f fsss g h i k l qqq r t h , n ggg p t e d u qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies

2. Shell Programming and Scripting

replacing field in specific line in a file

Hi, I know there are lots of threads on replacing text within files, usually using sed or awk. However, I find it hard to adapt examples that I found to my specific case. I am kind of new to UNIX and have hard times learning the syntax either for sed or awk so I would appreciate any help. Here's... (5 Replies)
Discussion started by: vytenis
5 Replies

3. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

4. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

5. Shell Programming and Scripting

Update specific field in a line of text file

I have a text file like this: subject1:LecturerA:10 subject2:LecturerA:40 if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example. The... (6 Replies)
Discussion started by: bmtoan
6 Replies

6. Shell Programming and Scripting

How to read particular line in file from specific column?

Hi...friends.... I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header I attached sample file..those... (12 Replies)
Discussion started by: nex_asp
12 Replies

7. Shell Programming and Scripting

To read specific line from a file

Hi, I have a ldif file like below: version: 1 dn: cn=Test Group,ou=Applications,dc=xyz,dc=com objectClass: groupOfUniqueNames objectClass: top cn: Test Group uniqueMember: uid=abc,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com dn: cn=Test Sub Group,cn=Test... (4 Replies)
Discussion started by: saurau
4 Replies

8. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

9. Shell Programming and Scripting

Add specific string to last field of each line in perl based on value

I am trying to add a condition to the below perl that will capture the GTtag and place a specific string in the last field of each line. The problem is that the GT value used is not right after the tag rather it is a few fields away. The values should always be 0/1 or 1/2 and are in bold in the... (12 Replies)
Discussion started by: cmccabe
12 Replies

10. Shell Programming and Scripting

awk to combine all matching fields in input but only print line with largest value in specific field

In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited, that are in $1 of gene which is just a single column of text. However only the line with the greatest $9 value in input needs to be printed. So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies
TCTMGR(1)							   Tokyo Cabinet							 TCTMGR(1)

NAME
tctmgr - the command line utility of the table database API DESCRIPTION
The command `tctmgr' is a utility for test and debugging of the table database API and its applications. `path' specifies the path of a database file. `bnum' specifies the number of buckets. `apow' specifies the power of the alignment. `fpow' specifies the power of the free block pool. `pkey' specifies the primary key of a record. `cols' specifies the names and the values of a record alternately. `name' specifies the name of a column. `op' specifies an operator. `expr' specifies the condition expression. `file' specifies the input file. tctmgr create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]] Create a database file. tctmgr inform [-nl|-nb] path Print miscellaneous information to the standard output. tctmgr put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path pkey [cols ...] Store a record. tctmgr out [-nl|-nb] [-sx] path pkey Remove a record. tctmgr get [-nl|-nb] [-sx] [-px] [-pz] path pkey Print the value of a record. tctmgr list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path Print the primary keys of all records, separated by line feeds. tctmgr search [-nl|-nb] [-ord name type] [-m num] [-sk num] [-kw] [-pv] [-px] [-ph] [-bt num] [-rm] [-ms type] path [name op expr ...] Print records matching conditions, separated by line feeds. tctmgr optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df] path [bnum [apow [fpow]]] Optimize a database file. tctmgr setindex [-nl|-nb] [-it type] path name Set the index of a column. tctmgr importtsv [-nl|-nb] [-sc] path [file] Store records of TSV in each line of a file. tctmgr version Print the version information of Tokyo Cabinet. Options feature the following. -tl : enable the option `TDBTLARGE'. -td : enable the option `TDBTDEFLATE'. -tb : enable the option `TDBTBZIP'. -tt : enable the option `TDBTTCBS'. -tx : enable the option `TDBTEXCODEC'. -nl : enable the option `TDBNOLCK'. -nb : enable the option `TDBLCKNB'. -sx : the input data is evaluated as a hexadecimal data string. -dk : use the function `tctdbputkeep' instead of `tctdbput'. -dc : use the function `tctdbputcat' instead of `tctdbput'. -dai : use the function `tctdbaddint' instead of `tctdbput'. -dad : use the function `tctdbadddouble' instead of `tctdbput'. -px : the output data is converted into a hexadecimal data string. -pz : do not append line feed at the end of the output. -m num : specify the maximum number of the output. -pv : print values of records also. -fm str : specify the prefix of keys. -ord name type : specify the order of the result. -sk num : specify the number of skipped records. -kw : print KWIC string. -ph : print hint information also. -bt : specify the number of benchmark tests. -rm : remove every record in the result. -ms type : specify the set operation of meta search. -tz : enable the option `UINT8_MAX'. -df : perform defragmentation only. -it type : specify the index type among "lexical", "decimal", "token", "qgram", and "void". -cd : create the number index instead of the string index. -cv : remove the existing index. -sc : normalize keys as lower cases. The operator of the `search' subcommand is one of "STREQ", "STRINC", "STRBW", "STREW", "STRAND", "STROR", "STROREQ", "STRRX", "NUMEQ", "NUMGT", "NUMGE", "NUMLT", "NUMLE", "NUMBT", "NUMOREQ", "FTSPH", "FTSAND", "FTSOR", and "FTSEX". If "~" preposes each operator, the logi- cal meaning is reversed. If "+" preposes each operator, no index is used for the operator. The type of the `-ord' option is one of "STRASC", "STRDESC", "NUMASC", and "NUMDESC". The type of the `-ms' option is one of "UNION", "ISECT", and "DIFF". This command returns 0 on success, another on failure. SEE ALSO
tcttest(1), tctmttest(1), tctdb(3), tokyocabinet(3) Man Page 2011-02-12 TCTMGR(1)
All times are GMT -4. The time now is 11:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy