Sponsored Content
Top Forums UNIX for Advanced & Expert Users awk for a line that contains someting in a field Post 302505368 by vgersh99 on Wednesday 16th of March 2011 07:11:19 PM
Old 03-16-2011
Quote:
Originally Posted by COKEDUDE
How would I do something like this when field 4 contains "John". I only want to print field 1 and 4 when when field 4 contains"John".

Code:
awk -F" " '{print $1 $4}

Code:
# $4 contains John
awk '$4 ~ "John" {print $1, $4}' myFile
# $4 is John
awk '$4 == "John" {print $1, $4}' myFile

These 2 Users Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK line by line instead of field by field?

I've been using a lot of awk lately for csv files. But I've been using awk for csv files that contain 32 fields per line. For the first time, I've been given a csv file that contains one field per line (13 fields in each csv file). I need to check that a specific field, or line contains a... (2 Replies)
Discussion started by: yongho
2 Replies

2. Shell Programming and Scripting

awk - if field is empty, move line to new file

I have a script with this statement: /usr/xpg4/bin/awk -F"" 'NR==FNR{s=$2;next}{printf "%s\"%s\"\n", $0, s}' LOOKUP.TXT finallistnew.txt >test.txt I want to include logic or an additional step that says if there is no data in field 3, move the whole line out of test.txt into an additional... (9 Replies)
Discussion started by: scriptr2be
9 Replies

3. Shell Programming and Scripting

awk append to one line if first field is the same

Hi all, How would I append the second field each time to one line if the first field is the same for example I have this data: 10430,187976 10430,251588 10430,262904 10430,275008 10430,279892 10430,275008 10430,303740 10430,318136 10430,336988 10430,350324 10430,373648 And I... (4 Replies)
Discussion started by: borderblaster
4 Replies

4. Shell Programming and Scripting

Replace line and field using SED and/or AWK or some other suggestion

QUESTION 1: How do you replace a specific line (i.e. line 4) with a new user defined line (i.e. the contents of SAMS’s name, history, math and English grades have been set already). I have been attempting to use SED (FYI: I don’t have GNU SED) or AWK, but haven’t had any luck. FYI: I am using... (1 Reply)
Discussion started by: thibodc
1 Replies

5. UNIX for Dummies Questions & Answers

Values with common field in same line with awk

Hi all ! I almost did it but got a small problem. input: cars red cars blue cars green truck black Wanted: cars red-blue-green truck black Attempt: gawk 'BEGIN{FS="\t"}{a = a (a?"-":"")$2; $2=a; print $1 FS $2}' input But I also got the intermediate records... (2 Replies)
Discussion started by: beca123456
2 Replies

6. UNIX for Dummies Questions & Answers

Help with awk, where line length and field position are variable

I have several questions about using awk. I'm hoping someone could lend me a hand. (I'm also hoping that my questions make sense.) I have a file that contains pipe separated data. Each line has similar data but the number of fields and the field position on each line is variable. ... (3 Replies)
Discussion started by: Cheese64
3 Replies

7. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

8. UNIX for Dummies Questions & Answers

Using awk to remove duplicate line if field is empty

Hi all, I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following: FILE: 1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100 2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY) 3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies

9. Shell Programming and Scripting

awk to remove line if field has symbols in it

Trying to use awk to remove a line only if $1 contains either ; or :. Thje awk below runs but no lines are removed. Thank you :). awk awk '$1 !~ /;/ || $1 !~ /:/ { print }' file file AARS2;TMEM151B 1 AASS 2 ABAT 3 ABCA1 3 ABCA10 1 ABCA12 2 ABCA13 1 ABCA13:AX746840 2 ABCA2 5 (5 Replies)
Discussion started by: cmccabe
5 Replies

10. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
Net::Hotline::User(3pm) 				User Contributed Perl Documentation				   Net::Hotline::User(3pm)

NAME
Net::Hotline::User - User object used internally by Net::Hotline::Client SYNOPSIS
use Net::Hotline::User; $user = new Net::Hotline::User; $user->nick("joe blow"); $user->icon(128); print "Nick: ", $user->nick(), " "; ... DESCRIPTION
Net::Hotline::User is a simple class for storing and retrieving user information, You should never have to create your own Net::Hotline::User objects when using Net::Hotline::Client. Getting and setting attributes is all that should be necessary. CONSTRUCTION
new SOCKET, NICK, LOGIN, ICON, COLOR With no arguments, creates a new Net::Hotline::User object with all attributes set to undef. The other option is to supply exactly 5 arguments as listed above. METHODS
All the Net::Hotline::User methods are simple attribute get/set routines. If given an argument, they set an attribute. In all cases, they return the current value of the attribute. color NUMBER The color of the user in the userlist. Values are numbers from 0 to 3. The hash HTLC_COLORS defined in Net::Hotline::Constants contains number to name color mappings (i.e. $HTLC_COLORS{2} is "red"). Example: use Net::Hotline::Constants qw(HTLC_COLORS); ... print $user->nick(), " is ", $HTLC_COLORS{$user->color()}, " "; icon NUMBER The user's icon number. Negative values are accepted. info TEXT User information as a block of "pretty-formatted" text. login TEXT The user's login name. nick TEXT The user's nickname in the userlist. socket NUMBER The user's unique socket number. User's are assigned a socket number whenthey connect to a Hotline server. AUTHOR
John C. Siracusa (siracusa@mindspring.com) COPYRIGHT
Copyright(c) 1999 by John Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2002-11-27 Net::Hotline::User(3pm)
All times are GMT -4. The time now is 11:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy