get ID number from one string name by using awk


 
Thread Tools Search this Thread
Top Forums Programming get ID number from one string name by using awk
# 1  
Old 05-11-2011
get ID number from one string name by using awk

Hi guys,

I am new to unix shell scripts. I have a file-A.txt which contained several names in "ABCo12345678.gz_to_ABCn12345678.gz" format. I want to extract the numbers in a "for" loop that means I can not use cut -c6-13 A.txt.Dose anyone know how to do it by using awk? Thank you so much.

shrimpj
# 2  
Old 05-11-2011
Try something like...
Code:
$ echo  "ABCo12345678.gz_to_ABCn12345678.gz" > file-A.txt

$ awk -F "[^0-9]*" '{print $2,$3}' file-A.txt
12345678 12345678

$

# 3  
Old 05-12-2011
Quote:
Originally Posted by Ygor
Try something like...
Code:
$ echo  "ABCo12345678.gz_to_ABCn12345678.gz" > file-A.txt

$ awk -F "[^0-9]*" '{print $2,$3}' file-A.txt
12345678 12345678

$

Thank you so much this is useful however, If it is possible do not send the string in to a file, I need use one line to apply this fuction as I will use for loop to read A.txt file.

So the ideal model would be
for f in A.txt; then
ID=???? (working on f varable to get ID)
if.....
Done

I apprieciate that awk have to excute on files. So do you have other solutions without using awk? Thank you in advance.
# 4  
Old 05-12-2011
if you are reading the file by other method and want to feed awk line by line, you could use the below logic

Code:
while read line
do
echo $line|awk -F "[^0-9]*" '{print $2,$3}'
done < input_file.txt

This User Gave Thanks to kumaran_5555 For This Post:
# 5  
Old 05-12-2011
Problem solved, thank you so very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Shell Programming and Scripting

Pass column number as variable to awk and compare with a string.

Hi All, I have a file test.txt. Content of test.txt : 1 vinay se 2 kumar sse 4 kishore tl I am extracting the content of file with below command. awk '$2 ~ "vinay" {print $0}' test.txt Now instead of hardcoding $2 is there any way pass $2 as variable and compare with a... (7 Replies)
Discussion started by: Girish19
7 Replies

3. Shell Programming and Scripting

awk - find number in string

I am trying to go through a file that has a few million lines. I want to only pull lines that contain a number anywhere in the ninth field, but it has to be after a "/" character. Here is my awk: awk -F\| '$9 ~ /\/*{1,}*/ {print $0}' file1 > file2 However, it is just printing out every... (3 Replies)
Discussion started by: dagamier
3 Replies

4. Shell Programming and Scripting

Getting awk Output as number instead of String

Hi All, I have a file a.txt, content as mentioned below: 22454750 This data in this control file and I have a variable called vCount which contains a number. I need to extract the 22454750 from the above file and compare with the variable vCount. If match fine or else exit. ... (5 Replies)
Discussion started by: Arun Mishra
5 Replies

5. Shell Programming and Scripting

Find number in string and delete it AWK

Hi all, i have some logs on my linux server that looks like this: CDR.2012-04-30:30-04-2012 14:09:36;123456456654;A;Greetings! Your amount is 42.24 dollars (without VAT) until 30/04/2012 11:00. CDR.2012-04-30:30-04-2012 14:09:36;12154878454212;A;Greetings! Your amount is 4203.2 dollars... (2 Replies)
Discussion started by: arrals_vl
2 Replies

6. Shell Programming and Scripting

awk string to number conversion

Can someone explain whats happening here: $ awk 'BEGIN {print (2.5 - 1)}' 1,5 2.5 - 1 is correctly calculated to 1,5 (using european locale) $ echo "2.5" | awk '{temp = $1 - 1; print temp}' 1 If i now pipe the string 2.5 through awk it seems at it truncates 2.5 to 2? What's the... (4 Replies)
Discussion started by: beow
4 Replies

7. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

8. UNIX for Dummies Questions & Answers

AWK - number of specified characters in a string

Hello, I'm new to using AWK and would be grateful for some basic advice to get me started. I have a file consisting of 10 fields. Initially I wish to calculate the number of . , ~ and ^ characters in the 9th field ($9) of each line. This particular string also contains alphabetical... (6 Replies)
Discussion started by: Olly
6 Replies

9. Shell Programming and Scripting

change awk string result to number

How could I change the lines with grep and awk to output a number instead of a string? case '2': @ L0 = 1 @ LN = `grep RS_D resample.in | awk '{print $3}'` @ P0 = 1 @ PN = `grep RS_D resample.in | awk '{print $5}'` # ||| fall through ||| Cheers (1 Reply)
Discussion started by: larne
1 Replies

10. Shell Programming and Scripting

awk/sed - getting string instead of number

Hi! I am writing a script handling downloading list of files and I have to check whether file is present locally and if not finished than continue downloading. To do so I have to compare sizes of remote file and local file. To check remote file size I have to parse something like this: ... (2 Replies)
Discussion started by: hrwath
2 Replies
Login or Register to Ask a Question