awk using sub , filtering textfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk using sub , filtering textfile
# 1  
Old 11-17-2012
awk using sub , filtering textfile

i have text file as below

Code:
 
CMF_COMP_ELEM_ GSM2_B71.WORLD_20121114130908.log   107496444 rows inserted into ALL_S1_CMF_COMP_ELEM.
CMF_COMP_ELEM_ GSM3_B71.WORLD_20121114130908.log   110729006 rows inserted into ALL_S1_CMF_COMP_ELEM.
CMF_COMP_ELEM_ GSM4_B71.WORLD_20121114130908.log   92549475 rows inserted into ALL_S1_CMF_COMP_ELEM.
CMF_COMP_ELEM_ GSM5_B71.WORLD_20121114130908.log   35606251 rows inserted into ALL_S1_CMF_COMP_ELEM.

i am expecting out put as below :

Code:
 
CMF_COMP_ELEM_ GSM2   107496444  
CMF_COMP_ELEM_ GSM3   110729006  
CMF_COMP_ELEM_ GSM4   92549475  
CMF_COMP_ELEM_ GSM5   35606251

please share the code ? below code not working


Code:
 
awk '{sub("_B71*log","",$1); print $1 $2 }'  inputfile

# 2  
Old 11-17-2012
Quote:
Originally Posted by only4satish
Code:
 
awk '{sub("_B71*log","",$1); print $1 $2 }'  inputfile

It should be $2

try

Code:
awk '{sub("_B71*.*.log","",$2); print $1,$2,$3 }'  file

# 3  
Old 11-17-2012
Code:
$ awk '{sub("_.*","",$2);print $1,$2,$3}' input.txt
CMF_COMP_ELEM_ GSM2 107496444
CMF_COMP_ELEM_ GSM3 110729006
CMF_COMP_ELEM_ GSM4 92549475
CMF_COMP_ELEM_ GSM5 35606251

# 4  
Old 11-17-2012
@pamu, its working

Code:
 
is * does  not  take . ?
 
why we need to have *.*. ?

# 5  
Old 11-17-2012
* is to match the 1 or more number of the matching characters.

.* is to match any character for 1 or more time.

Code:
$ echo "GSM2_B71.WORLD_20121114130908.log" | awk 'sub("B71*","")'
GSM2_.WORLD_20121114130908.log

$ echo "GSM2_B711111111111111111111" | awk 'sub("B71*","")'
GSM2_

$ echo "GSM2_B71.WORLD_20121114130908.log" | awk 'sub("B71.*","")'
GSM2_

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 11-17-2012
Quote:
Originally Posted by itkamaraj
* is to match the 1 or more number of the matching characters.

.* is to match any character for 1 or more time.
Must have been a typo.
The quantifier * is for matching 0 or more occurrences of the previous character/expression.
These 2 Users Gave Thanks to elixir_sinari For This Post:
# 7  
Old 11-18-2012
Code:
sed 's!\([^ ]*\) \{1,\}\([^_]*\)\([^ ]*\) \{1,\}\([^ ]*\).*!\1 \2 \4!g'  infile

This User Gave Thanks to complex.invoke 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 to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

2. Shell Programming and Scripting

awk print in one line after reading textfile with paragraphs

Hello everybody I have a text file which has the following format: nmm "text20140601.033954text" "text" "text" "text" , ... , "text" "text" , ... , Lat 36.3247 Lon 16.0588 Depth 8 "text", ... , "text" "text", ..., CovXX 1.65 CovYY 2.32 CovZZ 1.2 "text" , ..., "text nmm ... (6 Replies)
Discussion started by: phaethon
6 Replies

3. Shell Programming and Scripting

Variable filtering in awk

Hello all, can you explain why this filter does not work, it prints all the lines in the file: awk -v sel="TestString" 'sel' file while these work: awk '/TestString/' file awk -v sel="TestString" '$0~sel' file Thanks!:) (6 Replies)
Discussion started by: gio001
6 Replies

4. Shell Programming and Scripting

awk data filtering

I am trying to filter out some data with awk. If someone could help me that would be great. Below is my input file. Date: 10-JUN-12 12:00:00 B 0: 00 00 00 00 10 00 16 28 B 120: 00 00 00 39 53 32 86 29 Date: 10-JUN-12 12:00:10 B 0: 00 00 00 00 10 01 11 22 B 120: 00 00 00 29 23 32 16 29... (5 Replies)
Discussion started by: thibodc
5 Replies

5. Shell Programming and Scripting

filtering a numeric value which has '%' using awk

Hello Gurus, I have a requirement where I have to filter a value from some field which has 99% or greater than '99%'.. For ex: The Date (file -- sample.csv) will be like below Field1,Field2,Field3,Field4 860440512,844284992,16155520,99% 860440512,844284992,16155520,94%... (4 Replies)
Discussion started by: raghu.iv85
4 Replies

6. Shell Programming and Scripting

filtering with awk

i have question about awk ex: input.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 msn,1252468812,8.9 1252468923,gmail,12 live,1252468812,3.4 yahoo,1252468812,9.0 1252468929,msn,1.2 output.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 msn,1252468812,8.9... (3 Replies)
Discussion started by: zvtral
3 Replies

7. Shell Programming and Scripting

awk search strings from array in textfile

I am wanting to take a list of strings and loop through a list of textfiles to find matches. Preferably with awk and parsing the search strings into an array. // Search_strings.txt tag string dummy stuff things // List of files to search in textfile1.txt textfile2.txt The... (6 Replies)
Discussion started by: sdf
6 Replies

8. Shell Programming and Scripting

awk and sed filtering

Goo afternoon Sir'sould like to ask your help reagrding in this scenario using sed and awk. ******************************************************** Host:CDRMSAPPS1 Operating System:Linux 2.6.9-42.ELsmp Machine Type:UNIX Host Type:Client Version:5.1... (2 Replies)
Discussion started by: invinzin21
2 Replies

9. UNIX for Advanced & Expert Users

awk filtering ?

I have a Ques. Regarding awk I have few strings in a file, like.. ABC DEF_ABC GHI_ABC GHI Now I want string which has only 'ABC', not the part of any other string as it is also present in 'DEF_ABC' Output should be ABC Please guide me asap !! Thanks :b: (4 Replies)
Discussion started by: varungupta
4 Replies

10. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies
Login or Register to Ask a Question