get a field from a record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get a field from a record
# 1  
Old 03-01-2009
get a field from a record

I have a file as:
A,B,C,D,E
G,H,I,J,K

I need to find if fourth field is blank or has a space and print that line to other file.

I tried using awk but am not getting the desired result.
Pls help.
# 2  
Old 03-01-2009

Code:
awk -F, '$4 ~ /^ *$/' FILE > OTHERFILE

# 3  
Old 03-01-2009
Thank you.
# 4  
Old 03-01-2009
can I do something like this to add one more condition of checking if the 4th field is number or space or blank also:

awk -F, '$4 /^[]*||[0-9]*/' MYFILE >> OTHERFILE

I also want the other part i.e. I need to exclude all lines whose 4th field is space or blank or number:

MYFILE
a,b,c,d,e
a,b,c,2,r
c,d,f,,g
t,y,u, ,i

The new file should contain only first line. I tried using the below but I also get 3rd line

awk -F, '$4 /^ [A-Z]*/' MYFILE >> OTHERFILE

I need OTHERFILE to have only first record.
# 5  
Old 03-01-2009
Code:
 
awk -F, '$4 !~ /[0-9]/  && $4 !~ /[ ]/ && $4!=""' filename

# 6  
Old 03-02-2009
I have a similar question. I file a file with lines that look like this

02","00:52:19","knoxtnds1xpdn01","1","200","166.181.191.1","94728","1","174.156.215.192","7072804600 ","000007076943722","32313530343035333332","1","0","0","0A61E074","0","1235955139","68.28.81.76","10 .167.21.20","042300014D51","0","15","13","33","1","1","0","3","3","2","0","","","0","0","0","0","0", "","0","31OEqfgO","0","0","","","","","","","","","","","","","","","","",""

As you can see each field is separated by a comma. I'm trying to find all the lines that has "1" on the fourth field.

Any help would be appreciated
# 7  
Old 03-02-2009
Code:
awk -F, '$4 == "\"1\"" {print}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace value in each field until a certain character in each record?

Each record coming with column names. I have to replace them in each record as shown below TIME=20181219110000261|CHAN=FMBKHJBAAAADPCFNAAAAAABA|EVNT=SWIclst|VALU=Session FMBKHJBAAAADPCFNAAAAAABA started|SRC=NSS|UCPU=0|SCPU=0 Output should look like: ... (9 Replies)
Discussion started by: sudhakar1987
9 Replies

2. UNIX for Beginners Questions & Answers

Prepend 0 to a field in a record

Hi All, I have a file like below. In the field 9 I am having 14,014,3,001/009 on the records. I want to convert the field to a three digit value. For example 14 should 014 , 3 should 003 11050;11001;;CREDITTRANC;5293218;NRATL;;;11095;;-1;14;3;29=0000;1.25... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

3. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

4. Shell Programming and Scripting

Get last field specific record

i have file A as below contents --------------------------- Use descriptive thread titles when posting. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". For example, do not post questions For example, do not deliminated. output file as below:... (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

5. Shell Programming and Scripting

Remove \n at the beginning of a field in a record.

Hi, In my file, I have few records which are split across multiple lines. File 1: ===== james,\n pre-auth completed,in patient,\n Fac_Id:23451,ramson,Dallas Expected is: ========== james,pre-auth completed,in patient,Fac_Id:23451,ramson,Dallas (8 Replies)
Discussion started by: machomaddy
8 Replies

6. Shell Programming and Scripting

Replace third field of the first record in a file....

Hi, I am new to unix and am trying to do something below: I have a pipe delimited file with millions of records. I need to replace the third column of the first record to the number of lines in the file. How can I do that. Will appreciate any advice and help. Thanks Simi (3 Replies)
Discussion started by: simi28
3 Replies

7. Shell Programming and Scripting

how to replace field for each record

Hello, I have the following xml formatted file. I would like to get the newnumber field number and replace into customernumber for each record. For example: <XMLFORMAT> <customernumberR11>9</customernumberR11> ... (12 Replies)
Discussion started by: happyv
12 Replies

8. Shell Programming and Scripting

modify a few field of the record information

Hello, I have the following record in a text file, i would like modify some field: 1 - remove all space between ",", but the company name of word will not delete. Anyway, I can use the following statement to do it. 's/^ *//;s/ *, */,/g;s/ *$//' file 2. field #12, I need to modify to time... (11 Replies)
Discussion started by: happyv
11 Replies

9. UNIX for Dummies Questions & Answers

seaching field and getting complete record

hi, I have a file..... 1|3|4|5|6 1|3|4|4|5 now i ahave to search for value 4 in forth field and write that output to a file. if i do grep 4 file1 both lines are coming to output. can somebody help me building command. thanks and regards sandeep (4 Replies)
Discussion started by: mahabunta
4 Replies
Login or Register to Ask a Question