extracting character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers extracting character
# 1  
Old 05-14-2011
extracting character

This time I am trying to extract the number 10 from the following line. This number is subject to change and may be anything from 1 to 3 numerals in length, i.e. 1-999. Hence why I dont want to use 'cut' cmd.

The line I am working on is

Code:
GGSN-MIB::ggsnApnName.10 = STRING: open.internet

I have tried unsuccessfully using

Code:
 
alps$ awk -f"." '{ print $1 }' g11open.internet
GGSN-MIB::ggsnApnName.10
alps$ awk -f"." '{ print $2 }' g11open.internet
=

Can anyone help?
# 2  
Old 05-14-2011
Try something like this
Code:
awk '{match($0,/[0-9]+/);  print substr($0,RSTART,RLENGTH) } '

# 3  
Old 05-14-2011
Thanks for reply, unfortunately I get the following error

Code:
alps$ awk '{match($0,/[0-9]+/); print substr($0,RSTART,RLENGTH) } ' g11open.internet
awk: syntax error near line 1
awk: illegal statement near line 1

# 4  
Old 05-14-2011
Try:
Code:
awk -F'[ .]*' '{print $2}' g11open.internet

# 5  
Old 05-14-2011
Thanks Scrutinizer, unfortunately your cmd resonds with nothing

Code:
alps$ awk -F'[ .]*' '{print $2}' g11open.internet

# 6  
Old 05-14-2011
What is your OS ?
On Solaris please use nawk

I've tried it on HPUX v2 and 3 and Debian Linux, without syntax errors.
This User Gave Thanks to Peasant For This Post:
# 7  
Old 05-14-2011
Also, see if this makes a difference:
Code:
nawk -F'[ \t.]*' '{print $2}' g11open.internet

This User Gave Thanks to Scrutinizer 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

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Extracting character between 2 token - using only first match

Hello. ps -ae return I would like that the following command return 3214 echo " 3214 ? 00:00:01 acroread" | grep -o "]]]*" (5 Replies)
Discussion started by: jcdole
5 Replies

3. UNIX for Dummies Questions & Answers

Extracting 22-character strings from text using sed/awk?

Here is my task, I feel sure this can be accomplished with see/awk but can't seem to figure out how. I have large flat file from which I need to extract every case of a pairing of characters (GG) in this case PLUS the previous 20 characters. The output should be a list (which I plan to make... (17 Replies)
Discussion started by: Twinklefingers
17 Replies

4. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

5. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

6. Shell Programming and Scripting

Extracting the last character of a string

How to extract the last character of a string in bash? ---------- Post updated at 03:56 PM ---------- Previous update was at 03:55 PM ---------- Suppose "abcde" is a string. i want to extract the last character i.e. "e". (1 Reply)
Discussion started by: proactiveaditya
1 Replies

7. Shell Programming and Scripting

Extracting first character from a user response

I am using the following code in a CShell script to get a yes/no response from the user: echo "" echo -n "Do you want to archive your main level directory? <y> or n: " set main_answer = $< Is there a way to extract the first letter from the user's response and then perhaps convert that... (4 Replies)
Discussion started by: phudgens
4 Replies

8. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

9. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

10. Shell Programming and Scripting

Extracting a substring starting from last occurance of a string/character

Hi All, This is Ram. I'm new to this forum & new to shell scripts as well. I've a requirement in which I want to extract a substring from a given string based on last occurance of a character. for eg. I have a string of a file name with absolute path like... (2 Replies)
Discussion started by: krramkumar
2 Replies
Login or Register to Ask a Question