Print out just a word from the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print out just a word from the file
# 1  
Old 02-20-2005
Print out just a word from the file

Hi,
Would like to find a more suitable solution for the following. I have a file eg test.log. In this file, i have to find the line that has "Final rating" which is the starting of the line. I need to print out only 5.75 instead of the whole line using "grep". May I know what suitable command shall i use?

Final rating = 5.75 / 10.00

Regards and Thank you in advance.
# 2  
Old 02-20-2005
Code:
sed -ne '/^Final rating/s#^\([^=][^=]*\)=\([^/][^/]*\).*#\2#p' file

# 3  
Old 02-20-2005
Hi,
Thank you. Can I check with you whether this command is applicable in Linux?
# 4  
Old 02-20-2005
it should be as long as you have 'sed' available.
# 5  
Old 02-20-2005
Sorry i try but nothing comes out.

sed -ne '/^Final rating/s#^\([^=][^=]*\)=\([^/][^/]*\).*#\2#p' file

For this command,
May I know wat does /s stands for. Why is tat two [^=] and [^/]?

I know #\2#p is Print. Copy the pattern space to the standard output. Am I right?
# 6  
Old 02-20-2005
Quote:
Originally Posted by Kinki
Sorry i try but nothing comes out.

sed -ne '/^Final rating/s#^\([^=][^=]*\)=\([^/][^/]*\).*#\2#p' file

For this command,
May I know wat does /s stands for. Why is tat two [^=] and [^/]?

I know #\2#p is Print. Copy the pattern space to the standard output. Am I right?
it works just fine for this file based on your description:
Code:
Final rating = 5.75 / 10.00
foo
barr Final rating = 6.75 / 10.00
Final rating = 7.75 / 10.00

check your input file and make sure it really starts with 'Final rating' without any leading blanks.
# 7  
Old 02-20-2005
oic. Yes u are right. if there is leading Blank, how do u go about doing it?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

2. Shell Programming and Scripting

Extract the word from the file and print it

I have a file which I am reading and then I need to extract a particualr word and if it matches the line. 2015-01-22 07:30:17,814000 +0900 /INFO: - <ns2:virtualServerid="PH11PK" /> Means if the line contain Virtual server I need to extract the id . Code I wrote#!/usr/bin/perl ... (19 Replies)
Discussion started by: karan8810
19 Replies

3. UNIX for Advanced & Expert Users

Find 2 occurrences of a word and print file names

I was thinking something like this but it always gets rid of the file location. grep -roh base. | wc -l find . -type f -exec grep -o base {} \; | wc -l Would this be a job for awk? Would I need to store the file locations in an array? (3 Replies)
Discussion started by: cokedude
3 Replies

4. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

5. UNIX for Dummies Questions & Answers

How to print the specific word in a file.

Hi , My input file is below like that :- $cat abc.txt Service name: test_taf Service is enabled Server pool: test_tac Cardinality: 2 Disconnect: false Service role: PRIMARY Management policy: AUTOMATIC DTP transaction: false AQ HA notifications: true Failover type: SESSION... (3 Replies)
Discussion started by: sp001
3 Replies

6. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

7. Shell Programming and Scripting

print lines from a file containing key word

i have a file containing over 1 million records,and i want to print about 300,000 line containing a some specific words. file has content. eg 1,rrt,234 3,fgt,678 4,crf,456 5,cde,drt 6,cfg,123 and i want to print the line with the word fgt,crf this is just an example,my file is so... (2 Replies)
Discussion started by: tomjones
2 Replies

8. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

9. Shell Programming and Scripting

search a word in a xml file and print the out put

hi , i m having a html file and this file looks like this <ssl> <name>PIA</name> <enabled>true</enabled> <listen-port>39370</listen-port> </ssl> <log> <name>PIA</name> </log> <execute-queue> <name>weblogic.kernel.Default</name> ... (7 Replies)
Discussion started by: becksram123
7 Replies

10. Shell Programming and Scripting

Finding word in file then print the preceding....

Hi, I am looking for a way to find a particular word in a file then print a line that precedes this line, as well as this line. Sometimes in a log file there is only one word per line and I need to print one of the lines leading up to the single worded line. Example - I can grep for ouch... (5 Replies)
Discussion started by: g_jumpin
5 Replies
Login or Register to Ask a Question