Filter column using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter column using awk
# 1  
Old 11-14-2013
Filter column using awk

Hi all:

How do I use an `awk` like:

Code:
awk '{print $1 "\t" $2}' input

on the following input:

Code:
<head>medium-n</head>    nmod+ns+ns-map-n
<head>future-n</head>    of+n-the+ns-map-n


to achieve the following desired output:

Code:
medium-n    nmod+ns+ns-map-n
future-n  of+n-the+ns-map-n

# 2  
Old 11-14-2013
sed

Hey,

Try sth like this,

Code:
sed 's#<head>\(.*\)</head>#\1#' input_file

In awk, you can specify more than delimiter in -F option or FS variable.

Code:
awk -F'[<>\t]' '{print $3,$6;}' input_file

Cheers!
Ranga

Last edited by rangarasan; 11-14-2013 at 10:32 AM.. Reason: add awk solution
This User Gave Thanks to rangarasan For This Post:
# 3  
Old 11-14-2013
Code:
awk '{gsub(/<.?head>/, "", $0);print}' input_file

This User Gave Thanks to in2nix4life For This Post:
# 4  
Old 11-14-2013
Another approach:
Code:
awk '{gsub(/<[^>]*>/,X)}1' file

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter tab file based on column value

Hello I have a tab text file with many columns and have to filter rows ONLY if column 22 has the value of '0', '1', '2' or '3' (out of 0-5). If Column 22 has value '0','1', '2' or '3' (highlighted below), then remove anything less than 10 and greater 100 (based on column 5) AND remove anything... (1 Reply)
Discussion started by: nans
1 Replies

2. Shell Programming and Scripting

Filter first column duplicates

Dear All, I really enjoy your help or suggestion for resolving an issue. Briefly, I have a file like this: a b c a d e f g h k g h x y z If the first column has the same ID, for example a, just remove it. The output should be this: f g h k g h x y z I was thinking to do it... (11 Replies)
Discussion started by: giuliangiuseppe
11 Replies

3. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

4. Shell Programming and Scripting

awk to filter out lines containing unique values in a specified column

Hi, I have multiple files that each contain four columns of strings: File1: Code: 123 abc gfh 273 456 ddff jfh 837 789 ghi u4u 395 File2: Code: 123 abc dd fu 456 def 457 nd 891 384 djh 783 I want to compare the strings in Column 1 of File 1 with each other file and Print in... (3 Replies)
Discussion started by: owwow14
3 Replies

5. Shell Programming and Scripting

Filter more data in single column

Hi All, One of my source file column name RelationshipNumber. I need to filter below mentioned records in RelationshipNumber column. RelationshipNumber: S45678 D89763 Y09246579 A91234 If it is available in above mentioned column, then I need to print the entire line from my source... (2 Replies)
Discussion started by: suresh_target
2 Replies

6. Shell Programming and Scripting

awk filter based on column value (variable value)

Hi, I have a requirement to display/write the 3rd column from a file based on the value in the column 3. Ex: Data in the File (comma delimited) ID,Value,Description 1,A,Active 1,I,Inactive 2,S,Started 1,N,None 2,C,Completed 2,F,Failed I need to first get a list of all Unique IDs in... (7 Replies)
Discussion started by: kiranredz
7 Replies

7. Shell Programming and Scripting

Delete record filter by column

Dear friend, I have a file 2 files with column wise FILE_A ------------------------------ x,1,@ y,3,$ x,5,% FILE_B -------------------- x,1,@ i like to delete the all lines in FILE_A ,if first column available in FILE_B. output (in FILE_A) y,3,$ x,5,% (10 Replies)
Discussion started by: Jewel
10 Replies

8. Shell Programming and Scripting

AWK filter by column error

I want to found the parent process of the current parent process. I use the following script. ps -ef|grep -v grep |awk $3==$PPID print {$8} It is prompt the following error message: awk: 0602-500 Quitting The source line is 1. I am using AIX 6.1. Would you tell me what wrong of the... (2 Replies)
Discussion started by: cstsang
2 Replies

9. Shell Programming and Scripting

filter out certain column from a file

Hi all, I have this file, how can i remove the ID Number and Cardholder Name from the file ?  Thanks CT (4 Replies)
Discussion started by: CamTu
4 Replies

10. Shell Programming and Scripting

filter based on column value

I have a file with colon separated values.. the sample is attached below. No of fields in each record/line is dependent on the value of field53. What I need to do is to design a special filter based on specific requirement of some match of values in particular column or combination of columns. ... (2 Replies)
Discussion started by: rraajjiibb
2 Replies
Login or Register to Ask a Question