Sponsored Content
Full Discussion: Grep by column-Please help!
Top Forums UNIX for Dummies Questions & Answers Grep by column-Please help! Post 302071423 by amro1 on Wednesday 19th of April 2006 11:16:36 AM
Old 04-19-2006
Here...

Code:
cat file | cut -d "," -f 1,2 | grep 11

The command cat streams file to the standard output and we pipe it to cut command that extracts specific field from the file. "-d" sets the delimiter, in our case it is comma, "-f" species fields (columns) you want to extract (you can change/add your own list of cause) and eventually "grep" selects only these records that feature number 11 (it may be anything again).
Get "UNIX Essentials and UNIX Core" DVD it teaches things like that.

Hope it helps.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep by column number

I have a data file that is arranged like this: Marketing Ranjit Singh Eagles Dean Johnson FULL Marketing Ken Whillans Eagles Karen Thompson FULL Sales Peter RobertsonGolden TigersRich Gardener PART President Sandeep Jain Wimps Ken Whillans CONT... (7 Replies)
Discussion started by: hitman247m
7 Replies

2. Shell Programming and Scripting

Column grep

hi everyone, I am looking for an easy way to extract columns from a text file based on a regular expression, kind of like grep but searching and returning columns instead. for example, suppose i have the following file, 'file.txt': A B C D B 1 2 3 4 5 6 7 8 9 0 5 6 7 8 9 2 3 8 9 0 I... (6 Replies)
Discussion started by: css136
6 Replies

3. Shell Programming and Scripting

Grep but ignore first column

Hi, I need to perform a grep from a file, but ignore any results from the first column. For simplicity I have changed the actual data, but for arguments sake, I have a file that reads: MONACO Monaco ASMonaco MANUTD ManUtd ManchesterUnited NEWCAS NewcastleUnited NAC000 NAC ... (5 Replies)
Discussion started by: danhodges99
5 Replies

4. Shell Programming and Scripting

Grep 5 biggest column

please help, file1.txt id,week,ict,outgoing_call,blackberry_problem,gprs_problem,sms_problem,flash_problem,sinyal_lemah,blankspot,incoming_call,mms_problem,kualitas_suara,drop_call,data_probl em,cross_connect,connect_no_voice,vas_problem ,1,sumbagsel,96,127,52,70,28,29,21,18,18,8,5,3,0,0,3... (1 Reply)
Discussion started by: radius
1 Replies

5. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies

6. UNIX for Dummies Questions & Answers

Grep -v value in 2nd column

Trying to do a grep -v on a value in the 2nd column of text. So if the word apple appears in a line in the 2nd column, it would not show up when the file was cat. Seems like a simple enough operation but I just can't figure it out. Any help would be appreciated. Thanks in advance. Are apples... (4 Replies)
Discussion started by: jimmyf
4 Replies

7. Shell Programming and Scripting

How to grep from the third column?

PROL\tests_li004_developers:VAS:3543346:q34243,d3hs35,34bdf3,24sfgg,a3s234 Im trying to grep all text after VAS:3543346, so im trying to just have this q34243,d3hs35,34bdf3,24sfgg,a3s234 Im confused on how I would do this (7 Replies)
Discussion started by: ajetangay
7 Replies

8. Shell Programming and Scripting

Can grep a specific column?

Hello All I have an input file with data below. I would like to grep and display the data where 3rd column contains string or at least one character. Kindly please help me with this! Input: tjfa3|zznpou|224fdd.34.ff3.35 |Tiv|Otj|1 fgduul7|zznikj| ... (7 Replies)
Discussion started by: DoveLu
7 Replies

9. UNIX for Beginners Questions & Answers

Grep A Column Based On Column Name

I have a file with two columns separated by white space. Dog Cat fido sneaky dopey poptart ears whisker barky herd Trying to list the words under the column named Dog. Tried a few variations of awk but can't... (4 Replies)
Discussion started by: jimmyf
4 Replies

10. Shell Programming and Scripting

Grep values from column 2 in reference of column 1

Gents Is it possible to update the code to get the desired output files from the input list. I called variable to the first column. I need to consider the first column as key to grep the values in the second column according to the desired request. input list (attached ) output1 ... (12 Replies)
Discussion started by: jiam912
12 Replies
cut(1)								   User Commands							    cut(1)

NAME
cut - cut out selected fields of each line of a file SYNOPSIS
cut -b list [-n] [file...] cut -c list [file...] cut -f list [-d delim] [-s] [file...] DESCRIPTION
Use the cut utility to cut out columns from a table or fields from each line of a file; in data base parlance, it implements the projection of a relation. The fields as specified by list can be fixed length, that is, character positions as on a punched card (-c option) or the length can vary from line to line and be marked with a field delimiter character like <TAB> (-f option). cut can be used as a filter. Either the -b, -c, or -f option must be specified. Use grep(1) to make horizontal ``cuts'' (by context) through a file, or paste(1) to put files together column-wise (that is, horizontally). To reorder columns in a table, use cut and paste. OPTIONS
The following options are supported: list A comma-separated or blank-character-separated list of integer field numbers (in increasing order), with optional - to indicate ranges (for instance, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short for third through last field)). -b list The list following -b specifies byte positions (for instance, -b1-72 would pass the first 72 bytes of each line). When -b and -n are used together, list is adjusted so that no multi-byte character is split. -c list The list following -c specifies character positions (for instance, -c1-72 would pass the first 72 characters of each line). -d delim The character following -d is the field delimiter (-f option only). Default is tab. Space or other characters with special meaning to the shell must be quoted. delim can be a multi-byte character. -f list The list following -f is a list of fields assumed to be separated in the file by a delimiter character (see -d ); for instance, -f1,7 copies the first and seventh field only. Lines with no field delimiters will be passed through intact (use- ful for table subheadings), unless -s is specified. -n Do not split characters. When -b list and -n are used together, list is adjusted so that no multi-byte character is split. -s Suppresses lines with no delimiter characters in case of -f option. Unless specified, lines with no delimiters will be passed through untouched. OPERANDS
The following operands are supported: file A path name of an input file. If no file operands are specified, or if a file operand is -, the standard input will be used. USAGE
See largefile(5) for the description of the behavior of cut when encountering files greater than or equal to 2 Gbyte (2**31 bytes). EXAMPLES
Example 1: Mapping user IDs A mapping of user IDs to names follows: example% cut -d: -f1,5 /etc/passwd Example 2: Setting current login name To set name to current login name: example$ name=`who am i | cut -f1 -d' '` ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of cut: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were output successfully. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
grep(1), paste(1), attributes(5), environ(5), largefile(5), standards(5) DIAGNOSTICS
cut: -n may only be used with -b cut: -d may only be used with -f cut: -s may only be used with -f cut: cannot open <file> Either file cannot be read or does not exist. If multiple files are present, processing continues. cut: no delimiter specified Missing delim on -d option. cut: invalid delimiter cut: no list specified Missing list on -b, -c, or -f option. cut: invalid range specifier cut: too many ranges specified cut: range must be increasing cut: invalid character in range cut: internal error processing input cut: invalid multibyte character cut: unable to allocate enough memory SunOS 5.10 29 Apr 1999 cut(1)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy