awk seach and printing a particular pattern

Hi
i need a help for this.

the output of a command is like below

1         /tmp/x
2.2K     /tmp/y
3.2k     /tmp/z
1G       /tmp/a/b
2.2G    /tmp/c
3.4k    /tmp/d

Now i need to grep for the paths which are in GB..like below

1G       /tmp/a/b
2.2G    /tmp/c

pls suggest me, how can i do it by using awk?

Thanks,
siva

What have you tried?

I am not well in awk .

But i am able to grep for GB like this

command | awk '{print $1}' | grep -i G

but i am getting only 1 column, i need to grep G's is first column and their relative paths also.

Hello,

Following may help you.

awk '$1 ~ /G/ {print $0}' file_name

Output will be as follows.

1G       /tmp/a/b
2.2G    /tmp/c

Thanks,
R. Singh

2 Likes

i can do
command | awk '{print $1, $2}' | grep -i G...
but the problem is 'g' is also in paths ..i mean in second column...so it is giving where 'g' matches...
but i need the output like below

1G /tmp/a/b
2.2G /tmp/c

Hi Kumar,
You can try the following.

awk '/G/ {print $0}' filename

Hello Sdebasis,

Your suggestion will take the G in 2nd column also as follows. So we should only look for column 1st.

I added a G in 2nd column as follows.

$ cat file_name
1         /tmp/xG
2.2K     /tmp/y
3.2k     /tmp/z
1G       /tmp/a/b
2.2G    /tmp/c
3.4k    /tmp/d

Then it will show G for 2nd column also.

awk '/G/ {print $0}' chfile_name
1         /tmp/xG
1G       /tmp/a/b
2.2G    /tmp/c

We have to look for 1st column for same to avoid it seacrhing for 2nd column.

Thanks,
R. Singh

Just:

command |awk '$1 ~ /[0-9]G/'

Hi Ravinder,

You are right. :b:

Another approach:

awk '$1 ~ /G$/' file

Hello,

One more solution to same, may help.

awk '$1 !~ /G$/ {next} 1'  file_name

Output will be as follows.

1G       /tmp/a/b
2.2G    /tmp/c

Thanks,
R. Singh

Try :

$ awk 'substr($1,length($1)) == search' search='G' file
1G       /tmp/a/b
2.2G    /tmp/c
awk '$1 ~ /[0-9]+\.*[0-9]*G/'