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
# 8  
Old 04-01-2011
using -w, as the code in the above "#6"
# 9  
Old 04-01-2011
This is what I have in my text file called test

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

I only want to print the line in which the alphanumeric values in the line is set to 16
So the output should be this extracted from the 3 lines above

Code:
DSPLY_NAME "DISPLAY NAME"          3  NULL        ALPHANUMERIC       16  RMTES_STRING    16

Thanks

---------- Post updated at 01:41 PM ---------- Previous update was at 01:40 PM ----------

grep -w 'ALPHANUMERIC [0-9]*'
this prints all the lines in the file
Thanks

---------- Post updated at 01:42 PM ---------- Previous update was at 01:41 PM ----------

So basically I need t oread this huge file with tons of lines.
I need to print only lines in which the ALPHANUMERIC field is set to value of 16

As I showed in example above.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-01-2011 at 03:55 PM.. Reason: code tags, please!
# 10  
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
> " |grep -w 'ALPHANUMERIC 16'
DSPLY_NAME DISPLAY NAME 3 NULL ALPHANUMERIC 16 RMTES_STRING 16

This User Gave Thanks to yinyuemi For This Post:
# 11  
Old 04-01-2011
None of the suggested options worked
# 12  
Old 04-01-2011
Code:
grep 'ALPHANUMERIC  *16 ' test

had you used code tags, it would have been solved on the first try.
This User Gave Thanks to vgersh99 For This Post:
# 13  
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
> " |grep -w 'ALPHANUMERIC 16'
DSPLY_NAME DISPLAY NAME 3 NULL ALPHANUMERIC 16 RMTES_STRING 16

This works is there was only one sapce between ALPHANUMERIC and number 16. The problem is that the spaces between ALPHANUMERIC and 16 varies

So I have a Line that has

Code:
Line 1 >  ALPHANUMERIC 16
And another
Line 2 > ALPHANUMERIC      16

So It does not work becuase it does not match exact string

---------- Post updated at 02:05 PM ---------- Previous update was at 01:58 PM ----------

Thank u both -Sorry new to the Forums - NOT USING CODE TAGS
Will use them in future
Thanks

Last edited by vgersh99; 04-01-2011 at 04:00 PM.. Reason: once AGAIN - code tags!
# 14  
Old 04-02-2011
Code:
$ ruby -ne 'print if /ALPHANUMERIC\s*16/' file

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