Need help please with Grep/Sed command to extract text and numbers from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help please with Grep/Sed command to extract text and numbers from a file
# 1  
Old 04-01-2011
Need help please with Grep/Sed command to extract text and numbers from a file

Hello All,

I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created.

My problem is that sometimes 16 appears in other part of the line. I'm only interested to print lines that contain 16 which comes after ALPHANUMERIC
Basically the 16 is the lentgh of ALPHANUMERIC Charcters.
In the first line for example ALPHANUMERIC 16 << I need to print
lines that contain ALPHANUMERIC and that it is set t o16

Can u please help??? I tried many grep command but cannot get this working. I do not know perl and never worked with sed
Code:
DSPLY_NAME "DISPLAY NAME"          3  NULL        ALPHANUMERIC       16  RMTES_STRING    16
YTM_HIFLAG "YTM HIGH FLAG"       160  NULL        ALPHANUMERIC        1  RMTES_STRING     1
YTM_LOFLAG "YTM LOW FLAG"        161  NULL        ALPHANUMERIC        1  RMTES_STRING     1
BUYER_ID   "BUYER ID"            162  NULL        ALPHANUMERIC        4  RMTES_STRING     4
SELLER_ID  "SELLER ID"           163  NULL        ALPHANUMERIC        4  RMTES_STRING     4
MKT_MKR_NM "MRKT MAKER NAME"     214  NULL        ALPHANUMERIC       16  RMTES_STRING    16
ROW64_2    "MONROW 2"            216  NULL        ALPHANUMERIC       64  RMTES_STRING    64
ROW80_2    "IRGROW 2"            316  NULL        ALPHANUMERIC       80  RMTES_STRING    80


Last edited by Franklin52; 04-02-2011 at 02:58 PM.. Reason: Please use code tags
# 2  
Old 04-01-2011
Code:
 echo "DSPLY_NAME "DISPLAY NAME" 3 NULL ALPHANUMERIC 16 RMTES_STRING 16
YTM_HIFLAG "YTM HIGH FLAG" 160 NULL ALPHANUMERIC 1 RMTES_STRING 1
YTM_LOFLAG "YTM LOW FLAG" 161 NULL ALPHANUMERIC 1 RMTES_STRING 1
BUYER_ID "BUYER ID" 162 NULL ALPHANUMERIC 4 RMTES_STRING 4
SELLER_ID "SELLER ID" 163 NULL ALPHANUMERIC 4 RMTES_STRING 4
MKT_MKR_NM "MRKT MAKER NAME" 214 NULL ALPHANUMERIC 16 RMTES_STRING 16
ROW64_2 "MONROW 2" 216 NULL ALPHANUMERIC 64 RMTES_STRING 64
ROW80_2 "IRGROW 2" 316 NULL ALPHANUMERIC 80 RMTES_STRING 80" |grep -Po 'ALPHANUMERIC [0-9]+'
ALPHANUMERIC 16
ALPHANUMERIC 1
ALPHANUMERIC 1
ALPHANUMERIC 4
ALPHANUMERIC 4
ALPHANUMERIC 16
ALPHANUMERIC 64
ALPHANUMERIC 80

# 3  
Old 04-01-2011
Hi & thanks

But when I type ( where test is the name of my text file )
Code:
grep -Po 'ALPHANUMERIC' [0-9]+' test
>

I just get the prompt > ?

I'm in bash? does that make a difference?

---------- Post updated at 01:33 PM ---------- Previous update was at 01:31 PM ----------

sorry Imade a typo
Code:
grep -Po 'ALPHANUMERIC [0-9]+' test

I type the above and nothing happens?

Last edited by Franklin52; 04-02-2011 at 02:57 PM.. Reason: Please use code tags
# 4  
Old 04-01-2011
remove the single quote after "ALPHANUMERIC", and try again
# 5  
Old 04-01-2011
I also need to print the entire line from begining to end
not just APLHANUMERIC 16 ?
I need the full line like in thei example

RELNEWS "RELATED NEWS" 5757 NULL ALPHANUMERIC 16 RMTES_STRING 16

thanks
# 6  
Old 04-01-2011
Code:
grep -w 'ALPHANUMERIC [0-9]*'

# 7  
Old 04-01-2011
this is what I types and it produces blank- Also I need t oprint the entire line
Code:
grep -o 'ALPHANUMERIC [0-9]*' test


Last edited by Franklin52; 04-02-2011 at 02:58 PM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script extract text from txt file with grep

All, I require a script that grabs some text from the gitHub API and will grep (or other function) for a string a characters that starts with (") quotes followed by two letters, may contain a pipe |, and ending with ) . What i have so far is below but it's not returning anything. ... (4 Replies)
Discussion started by: ChocoTaco
4 Replies

2. UNIX for Dummies Questions & Answers

sed - extract a group of Letters/numbers

I have a file with hundreds of lines in it. I wanted to extract anything that matches the following: KR followed by 4 digits: example KR1201 cat list | sed "s///g" Is the closest I've come, and obviously it is not what I want. This would remove all of the items that I want and leave me... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

Need to extract only decimal numbers for a glob of text

If you have a look at this thread, you'll see that users have been posting the output a script which are numbers that range from 2 to 5 decimal places. If I dump this entire thread to txt file, how can I: 1) Delete everything except for numbers of the following formats (where 'x' is a digit and... (5 Replies)
Discussion started by: graysky
5 Replies

4. Shell Programming and Scripting

sed - extract text from xml file

hi, please help, i have an xml file, e.g: ... <tag> test text asdas="${abc}" xvxvbs:asdas${222}sdad asasa="${aa_bb_22}" </tag> ... i want to extract all "${...}", e.g: ${abc} ${222} ${aa_bb_22} thank you. (2 Replies)
Discussion started by: gioni
2 Replies

5. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

6. Shell Programming and Scripting

Extract numbers from text file work out average

Just wondering if someone could assist me with shell script I'm trying to write. I need to read the final column of a text file (shown below) and workout what the average number is. The text file will have a variable number of lines, I just want the script to pull out the values in the final field... (14 Replies)
Discussion started by: rich@ardz
14 Replies

7. UNIX for Advanced & Expert Users

bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this: clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6... (3 Replies)
Discussion started by: Pioneer1976
3 Replies

8. Shell Programming and Scripting

sed to extract only floating point numbers from HTML

Hi All, I'm trying to extract some floating point numbers from within some HTML code like this: <TR><TD class='awrc'>Parse CPU to Parse Elapsd %:</TD><TD ALIGN='right' class='awrc'> 64.50</TD><TD class='awrc'>% Non-Parse CPU:</TD><TD ALIGN='right' class='awrc'> ... (2 Replies)
Discussion started by: pondlife
2 Replies

9. Shell Programming and Scripting

Sed to grep only numbers in string

Hi, I would like to get only number in the following strings. var1="Type20" var2="type 3" var3="value 2" var4="Type 1 Datacenter Hall 2" I would like to extract output as 20 from var1 and 3 from var2,2 from var3 and 1 from var4. Appreciate any one help asap.. Regards, Aji (5 Replies)
Discussion started by: ajilesh
5 Replies

10. Shell Programming and Scripting

grep or awk problem, unable to extract numbers

Hi, I've trouble getting some numbers from a html-file. The thing is that I have several html-logs that contains lines like this: nerdnerd, how_old_r_u:45782<br>APPLY: <hour_second> Verification succeded This is some of what I've extracted from a html file but all I really want is the number... (7 Replies)
Discussion started by: baghera
7 Replies
Login or Register to Ask a Question