Sponsored Content
Top Forums Shell Programming and Scripting How to convert a 2 digit to 4 digit Post 302188305 by jisha on Wednesday 23rd of April 2008 06:23:43 AM
Old 04-23-2008
CPU & Memory A problem with awk

Hi All,

I have a file in teh format given below:

catanimal 0 animal 90 number90 cat_number_name
catanimal 1 animal 91 number91 cat_animal_name
catanimal 2 animal 92 number92 cat_name_animal


kiwiani 0 bird 90 number90 kiwi_number_name
kiwiani 1 bird 91 number91 kiwi_animal_name
kiwiani 2 bird 92 number92 kiwi_name_animal

cat 0 animal 90 number90 cat_number_name
cat 1 animal 91 number91 cat_animal_name
cat 2 animal 92 number92 cat_name_animal

bat 0 animal 90 number90 bat_number_name
bat 1 animal 91 number91 bat_animal_name
bat 2 animal 92 number92 bat_name_animal

When i use awk '$1 ~ /bat/ {if ($2==0){print $5} } ' file , i get the
result i want
But if i give awk '$1 ~ /cat/ {if ($2==0){print $5} } ' file, I get
result for $1=cat and $1=catanimal where as i want the result for only $1="cat"

Thanks in advance
JS
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

why "expr "${REPLY}" : '\([1-9][[:digit:]]*\)" can figure out whether it is a digit?

I found below script to check whether the variable is a digit in ksh. ############################ #!/bin/ksh REPLY="3f" if ]*\)'` != ${REPLY} && "${REPLY}" != "0" ]] then print "is digit\n" else print "not digit\n" fi ############################ Although it works fine, but... (6 Replies)
Discussion started by: sleepy_11
6 Replies

2. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies

3. Shell Programming and Scripting

Single digit date to double digit date.

I have a var storing date var=`date` Now the date is returned as Mon Feb 2 00:25:48 PST 2009 Is there any way to check the date field alone ("2" in above case) and if its a single digit then add a prefix 0 to it and store the result in same variable "var" My intention in above case is... (3 Replies)
Discussion started by: villain41
3 Replies

4. Shell Programming and Scripting

how to delete 2 digit

I have string like abcdefgh i want to delete first two digit of the string. output should be cdefgh plz give me solution (3 Replies)
Discussion started by: Gopal_Engg
3 Replies

5. Programming

Find out 2^n+1 , where n is a 3 digit number

I have to write a c program which takes a 3 digit number n and calculates the value of (2^n)+1 and then determines the number is prime or not. I have tried to first calculate the value of 2^n and then adding one to it and then apply the logic of prime number. but the ultimate problem is that... (7 Replies)
Discussion started by: agrawal.prachi
7 Replies

6. Programming

[:digit:]

Hi, Does anybody know what the below means: I have a program containing the following and am trying to understand what it does: temp=$(echo $count2 | tr -cd ) Cheers Paul Please start using code tags (2 Replies)
Discussion started by: runnerpaul
2 Replies

7. Shell Programming and Scripting

grepping by digit

Hi all, Need your help here. I have a file with thousand of lines, as shown in example below KDKJAA 98324 OIDSAJ 324 KJAJAK 100 KJKAJK 89 JOIJOI 21 JDKDJL 12 UOIUOD 10 UDUYDS 8 UIUHKK 6 I would like to grep using... (5 Replies)
Discussion started by: masterpiece
5 Replies

8. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

9. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

10. Shell Programming and Scripting

Delta from the first digit

Thanks of your suggestions i was able to calculate the delta between some numbers in a column file with . awk 'BEGIN{last=0}{delta=$1-last; last=$1; print $0" "delta}' the file was like 499849120.00 500201312.00 500352416.00 500402784.00 500150944.00 499849120.00 500150944.00... (3 Replies)
Discussion started by: Board27
3 Replies
libifstat-config(1)					      General Commands Manual					       libifstat-config(1)

NAME
libifstat-config - get information about the installed version of libifstat SYNOPSIS
libifstat-config [--cflags] [--exec-prefix] [--libs] [--prefix] [--version] DESCRIPTION
libifstat-config prints the compiler and linker flags required to compile and link programs that use the libifstat Application Programmer Interface. EXAMPLES
To print the version of the installed distribution of libifstat, use: libifstat-config --version To compile a program that calls the libifstat Application Programmer Interface, use: cc `libifstat-config --cflags --libs` program.c OPTIONS
--cflags Print the compiler flags that were used to compile liblibifstat. --exec-prefix Print the directory under which target specific binaries and executables are installed. --libs Print the linker flags that are needed to link a program with liblibifstat. --version Print the version of the libifstat distribution to standard output. COPYRIGHT
The license can be found in the file /usr/share/common-licenses/GPL. AUTHORS
This package was debianized by the upstream Author Gael Roualland <gael.roualland@dial.oleane.com>. This manual page was adapted from the animal-config manual page of the animal package which in turn was adapted from Magick-config manual page of the ImageMagick package. libifstat 13 Jun 2004 libifstat-config(1)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy