Sponsored Content
Top Forums Shell Programming and Scripting Awk find in columns with "if then" statement and print results Post 302588376 by charles33 on Sunday 8th of January 2012 08:06:03 PM
Old 01-08-2012
Awk find in columns with "if then" statement and print results

I have a file1.txt

file1.txt
Code:
F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true"
F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true"
U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"
V-120009218","Pincher","1-1-1-","grey","yes","yes","1-0-","Worcester","MA","true"

Basicly I need to check "column 3 and column 7":
If F- found than Female.
If no F- found check M-, if found than Male
If neither M- or F- found than Unknown

Than print it like result1.txt.

result1.txt
Code:
F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true","Female"
F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true","Female"
U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true","Male"
V-120009218","Pincher","1-1-1-","grey","yes","yes","1-0-","Worcester","MA","true","Unknown"

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

3. Shell Programming and Scripting

Results of "find" to an array

I am looking to search a directory for a folder or file and when it finds any hits I want it to store those hits in an array so I can work with those hits later on. I have been trying to do something like this but it isn't putting results into an array like I would like, is it syntax or is this... (8 Replies)
Discussion started by: tret
8 Replies

4. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

5. Shell Programming and Scripting

awk statement to match all lines starting with "#"

Looking for awk statement that will match all lines starting with "# " if ( $1 == \^"#" ) Input file: # of the server. If you would like to set these, please take out the # pound (#) sign in front of one or all severities and set it equal to # severity desired. For example, FATAL=3 #... (2 Replies)
Discussion started by: Arsenalman
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

sort, columns, no result! can I print files of "planes"?

hi, please can I ask you for some help? I have data from 3D situation, x y z value I'd like to use gnuplot to generate maps of the value in the planes z=0 to z=1 for example, my file looks like -0,012 0,0060 0,0 0,13972813076023477 -0,012 0,0064319163 4,2894483E-4 ... (1 Reply)
Discussion started by: kocour
1 Replies

8. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

10. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies
LIGHT_CORRECT(1)					      General Commands Manual						  LIGHT_CORRECT(1)

NAME
light_correct - correct illumination errors on set of images SYNOPSIS
light_correct grey image1 image2 image3 ... DESCRIPTION
The first argument should be an image of a piece of grey card, subsequent arguments should be images taken with the same lighting set-up which need correcting. The corrected images are written to files prefixed with "ic_". For example, suppose you have a directory with the following files in: example% ls dat1.1.v dat1.2.v dat2.1.v dat2.2.v dat3.1.v dat3.2.v dat4.1.v dat4.2.v grey.v then run light_correct like this: example% light_correct grey.v dat*.v to generate this: example% ls dat1.1.v dat1.2.v dat2.1.v dat2.2.v dat3.1.v dat3.2.v dat4.1.v dat4.2.v grey.v ic_dat1.1.v ic_dat1.2.v ic_dat2.1.v ic_dat2.2.v ic_dat3.1.v ic_dat3.2.v ic_dat4.1.v ic_dat4.2.v light_correct works by smoothing out the grey card image, finding grey-mean/pixel for each point, and then multiplying the result by all the following images. It also removes any .desc files it generates, to avoid problems with im_global_balance(3). RETURN VALUE
returns 0 on success and non-zero on error. SEE ALSO
header(1), vips(1) COPYRIGHT
The National Gallery and Birkbeck College, 1989-1996. 14 Oct 1996 LIGHT_CORRECT(1)
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy