Use grep/awk to remove part of column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use grep/awk to remove part of column
# 1  
Old 11-18-2013
Use grep/awk to remove part of column

hi all,
how can i use
Code:
grep

or
Code:
awk

to clean the following input data:

Code:
n<>the<>96427210 861521305 123257583 
n<>obj<>79634223 861521305 79634223 
n<>nmod<>68404733 861521305 68422718

where the desired results is to remove all non-numeric characters?:

Code:
96427210 861521305 123257583 
79634223 861521305 79634223 
68404733 861521305 68422718

# 2  
Old 11-18-2013
With some assumptions..

Code:
$ awk -F ">" '{ print $NF}' file

96427210 861521305 123257583
79634223 861521305 79634223
68404733 861521305 68422718

This User Gave Thanks to pamu For This Post:
# 3  
Old 11-18-2013
if you want to remove all non-numeric data (excluding spaces) try this:
Code:
sed 's/[^0-9 ]//g' file

This User Gave Thanks to Subbeh For This Post:
# 4  
Old 11-18-2013
Perl
Code:
perl -pe 's/[^0-9\s]//g' filename

This User Gave Thanks to pravin27 For This Post:
# 5  
Old 11-18-2013
Code:
$ awk 'gsub("[^0-9 ]","")' a.txt
96427210 861521305 123257583 
79634223 861521305 79634223 
68404733 861521305 68422718

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 11-18-2013
One more way to get expected output

Code:
$ cat <<eof | awk 'gsub(/[[:alpha:]]|[[:punct:]]/,x)'
n<>the<>96427210 861521305 123257583 
n<>obj<>79634223 861521305 79634223 
n<>nmod<>68404733 861521305 68422718
eof

96427210 861521305 123257583 
79634223 861521305 79634223 
68404733 861521305 68422718

for file use like this
Code:
$ awk 'gsub(/[[:alpha:]]|[[:punct:]]/,x)' file

OR
Code:
$ tr -d '[[:alpha:]]|[[:punct:]]' <file

OR
Code:
$ tr -cd '[:digit:]  \n' <file


Last edited by Akshay Hegde; 11-18-2013 at 09:51 AM..
These 2 Users Gave Thanks to Akshay Hegde 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

How can I remove first column with awk?

cat input.txt a x b y c z Expected output x y z (11 Replies)
Discussion started by: cola
11 Replies

2. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies

3. Shell Programming and Scripting

Grep/awk part of info of a column

I have a question that I am at a loss to solve. I have 3 column tab-separated data, such as: abs nmod+n+n-commitment-n 349.200023 abs nmod+n+n-a-commitment-n 333.306429 abs into+ns-j+vn-pass-rb-divide-v 295.57316 abs nmod+n+ns-commitment-n 182.085018 abs nmod+n+n-pledge-n ... (2 Replies)
Discussion started by: owwow14
2 Replies

4. Shell Programming and Scripting

[awk] grep a part of filename as entry file

hi all, i need to combine these files into one csv file. Bounce_Mail_Event_Daily_Report_01_Jul_2012.csv Bounce_Mail_Event_Daily_Report_02_Jul_2012.csv Bounce_Mail_Event_Daily_Report_03_Jul_2012.csv Bounce_Mail_Event_Daily_Report_04_Jul_2012.csv... (10 Replies)
Discussion started by: makan
10 Replies

5. Shell Programming and Scripting

awk to replace part of a column

dear all, I'm trying to use Awk to eliminate the last two characters from the first column in a file. This two characters are "-1" and I need to eliminate them from each row that I have in the files. The files have two columns and look like: ID_090-1 2 ID_3787-1 4 ID_0098-1 1 ID_12-1 4 I... (4 Replies)
Discussion started by: gabrysfe
4 Replies

6. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

7. Shell Programming and Scripting

Changing part of column value with AWK

Hi All , Here is my req I am extracting a column value and I want to change part of its value according to user input Say the column I extracted is of 15 digits and I want to change the 11th to 14th position with user input 4 digit value Example column value 111111111111111 user input... (8 Replies)
Discussion started by: Pratik4891
8 Replies

8. Shell Programming and Scripting

Remove part of a column in a text file

I have a text file with delimiter "|" and sometimes the zipcode is in "5th" column or "6th" column. I want to scan the file and remove the "-2323" from the zipcode which has zip+4 digits From blah|blah|foo|bar||blah|945523-232|USA blah|blah|foo|bar||blah|foo|94555-2323|USA To... (8 Replies)
Discussion started by: gubbu
8 Replies

9. Shell Programming and Scripting

Remove certain parameters from column using awk or sed

I have a text file Nov 1 LOG_10_000000343.gzip_COMPLETE 2910 server.log.3 Nov 4 LOG_10_000000343.gzip_COMPLETE 2910 server.log.4 Dec 5 LOG_10_000000343.gzip_blah 2910 server.log.5 Jul 6 LOG_10_000000343.gzip_ERROR 2910 server.log.1 I need to convert this to Nov 1 LOG_10_000000343.gzip... (3 Replies)
Discussion started by: gubbu
3 Replies

10. Shell Programming and Scripting

awk remove column with conditions?

Folks: I have a file which has 3 columns. Using awk I want to remove rows from column 3 (Col3 <> A) where it is not equal to A. All columns are seperated by "|". Col1|Col2|Col3|Col4 1 | 2 | A | 4 2 | 3 | A | 5 3 | 4 | B | 6 4 | 5 | A | 7 5 | 6 | ... (3 Replies)
Discussion started by: pr2003
3 Replies
Login or Register to Ask a Question