Visit Our UNIX and Linux User Community


awk seach and printing a particular pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk seach and printing a particular pattern
# 1  
Old 03-04-2014
awk seach and printing a particular pattern

Hi
i need a help for this.

the output of a command is like below
Code:
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
Code:
1G       /tmp/a/b
2.2G    /tmp/c

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

Thanks,
siva

Last edited by Franklin52; 03-04-2014 at 06:37 AM.. Reason: Please use code tags
# 2  
Old 03-04-2014
What have you tried?
# 3  
Old 03-04-2014
I am not well in awk .

But i am able to grep for GB like this

Code:
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.
# 4  
Old 03-04-2014
Hello,

Following may help you.

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


Output will be as follows.

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

Thanks,
R. Singh
These 2 Users Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 03-04-2014
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
# 6  
Old 03-04-2014
Hi Kumar,
You can try the following.


awk '/G/ {print $0}' filename
# 7  
Old 03-04-2014
Quote:
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.

Code:
$ 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.

Code:
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

Previous Thread | Next Thread
Test Your Knowledge in Computers #456
Difficulty: Easy
An application programming interface (API) is a graphical-based interface for viewing client-server data.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX awk pattern matching and printing lines

I have the below plain text file where i have some result, in order to mail that result in html table format I have written the below script and its working well. cat result.txt Page 2015-01-01 2000 Colors 2015-02-01 3000 Landing 2015-03-02 4000 #!/bin/sh LOG=/tmp/maillog.txt... (1 Reply)
Discussion started by: close2jay
1 Replies

2. Shell Programming and Scripting

Help! Printing out CSV output from awk Pattern Match

Hi, I need to search for a word using Awk and print out the line the word is in and every line after the search phrase until I hit this #------------. Then I need to send it to a csv file. So basically the input file format is like this:... (1 Reply)
Discussion started by: An0mander
1 Replies

3. Shell Programming and Scripting

awk pattern match not printing desired columns

Hi all, I'm trying to match the following two files with the code below: awk -F, 'NR==FNR {a=$0; next} ($12,$4) in a {print $12,$1,a}' OFS="," file4.csv file3.csv but the code does not print the entire row from file4 in addition to column 12 and 1 of file3. file4: o,c,q,co,ov,b... (1 Reply)
Discussion started by: bkane3
1 Replies

4. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

5. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

6. Shell Programming and Scripting

Printing the continuous occurence of pattern using awk ?

Hello all, I have a input file like this. input file --------------- abc ab001 + ab002 zca acb ab006 + ab007 caz cba ab003 + ab004 zca bac ab004 - ab005 zac bca ab002 - ab003 cza cba ab005 + ab006 acz cba ab005 ... (5 Replies)
Discussion started by: admax
5 Replies

7. Shell Programming and Scripting

NAWK - seach pattern for special characters - } dbl qt - sng qt

i'm puzzled.... trying to look for the pattern }"'. but the below code returns to me the message below (pattern is curley queue + dbl qt + sng qt + period) nawk -v pat="\}\"\'\."' { if (match($0, pat)) { before = substr($0,1,RSTART-1); ... (11 Replies)
Discussion started by: danmauer
11 Replies

8. Shell Programming and Scripting

AWK seach for exact word in certain column

Can anyone help me how I will extract all lines in a file where the word "worker" or "co-worker" in 2nd column exist. There are also word in 2nd column like "workers" or "worker2" but I don't want to display those lines. Appreciate any help in advance! Thank you! (5 Replies)
Discussion started by: Orbix
5 Replies

9. Shell Programming and Scripting

Is it better to grep and pipe to awk, or to seach with awk itself

This may just be a lack of experience talking, but I always assumed that when possible it was better to use a commands built in abilities rather than to pipe to a bunch of commands. I wrote a (very simple) script a while back that was meant to pull out a certain error code, and report back what... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

10. Shell Programming and Scripting

Printing out pattern in line

I've scoured the forum and found similar problems but I can't seem to adapt them to help me with my cause. This is a two-part question. I have a multi line file generated by ps | -ef I need to print out a certain type of pattern. The pattern is part static and part dynamic. It is a... (3 Replies)
Discussion started by: FK_Daemon
3 Replies

Featured Tech Videos