Extract number from column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract number from column
# 1  
Old 05-04-2017
Extract number from column

I have a lot of file with a lot of lines following the same pattern
the lines go like this:
Code:
alpha_9/output- -413.74928476 2.6116

and I want it to be:
Code:
9 -413.74928476 2.6116

thanks for the help

Last edited by Scrutinizer; 05-04-2017 at 06:57 AM.. Reason: code tags
# 2  
Old 05-04-2017
Hi, try:
Code:
awk '{split($1,F,"[_/]"); $1=F[2]}1' file

# 3  
Old 05-04-2017
It worked Smilie

tyvm
# 4  
Old 05-04-2017
Try also
Code:
awk 'gsub (/[^0-9]/, "", $1)' file

# 5  
Old 05-04-2017
Quote:
Originally Posted by RudiC
Try also
Code:
awk 'gsub (/[^0-9]/, "", $1)' file

working as well
thanks

Can u explain the different so I can choose the better one for me?
# 6  
Old 05-04-2017
One splits the first field's contents at _ and / and prints the second element of the result. The other removes all non-digit characters and assumes there are such so gsub's return value is non-zero (= TRUE) so it does the default action: print.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get extract and replace column with link in a column where it exists

hi i have sample data a,b,c,d,e,g h http://mysite.xyx z,b,d,f,e,s t http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing output expected is a,b,c,d,e,http://mysite.xyx z,b,d,f,e,http://123124# a,b,c,i,m,nothing d,i,j,e,w,nothing i can get only links using grep -o 'http.*' i... (8 Replies)
Discussion started by: zozoo
8 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

3. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

4. UNIX for Dummies Questions & Answers

How to extract a number from a statement?

Hi, i want to extract a number from a statement. 03/07/14 00:58:41 CRPr::CopyTotable inserted 3501 rows into table Now i want to assign 3501 to a variable. This number may change every time. (5 Replies)
Discussion started by: arghadeep adity
5 Replies

5. Shell Programming and Scripting

Help with compare two column and print out column with smallest number

Input file : 5 20 500 2 20 41 41 0 23 1 Desired output : 5 2 20 0 1 By comparing column 1 and 2 in each line, I hope can print out the column with smallest number. I did try the following code, but it don't look good :( (2 Replies)
Discussion started by: perl_beginner
2 Replies

6. Shell Programming and Scripting

How to extract port number?

Hi my code is as follow: stringA=`cat /s01/oracle/11.2/network/admin/listener.ora | grep "PORT"` stringB=`cat $ORACLE_HOME/network/admin/listener.ora | grep "PORT"` stringC="PORT" echo ${stringA} echo ${stringB} echo ${stringC} position=`expr index "$stringB" "stringC"` echo... (2 Replies)
Discussion started by: jediwannabe
2 Replies

7. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

8. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

9. Shell Programming and Scripting

Extract Number

I am trying to extract the numbers from the strings. Lakers win 80% of the games 24 numbered Kobe scores 90% from free throw line Chances of Lakers winning championship is 100% I have data like this. and am looking to extract the % 80% 90% 100% (6 Replies)
Discussion started by: grajp002
6 Replies

10. Shell Programming and Scripting

Extract the highest number out

Hi Gurus, I've using HPUX B.11.23 U ia64 with shell = sh. I've been having some problem get the highest number of this script. Actually I wanted to get the highest number from this listing (TEST123 data and based on this highest number, there will be email being sent out. For example,... (6 Replies)
Discussion started by: superHonda123
6 Replies
Login or Register to Ask a Question