Print last 2 letters in a word


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print last 2 letters in a word
# 1  
Old 09-08-2008
Print last 2 letters in a word

Hi,

I have a file which has the below information

tm.orbit72
tm.orbit12
tm.orbit78
tm.orbitye

I want to print the last two letters in the above file. Please let me know how can i do that.
# 2  
Old 09-08-2008
With sed:

Code:
sed 's/.*\(..\)/\1/' file

Regards
# 3  
Old 09-08-2008
Hi,

It works great thanks.. I got a file like this.

orbits12
orbits13
oribits16

Now the output is like this
12
13
16

I want to also sum this all.
# 4  
Old 09-08-2008
Homework?
# 5  
Old 09-08-2008
No Homework..

No I am devoloping some script..which needs some input from this files.I dunno how to get this.. I know expr command but dont know how to sum the lines..
# 6  
Old 09-08-2008
Code:
perl -lne'
  print /(..)$/ and $t += $1;
    print $t if eof
    ' filename

For more than 2 digits:

Code:
perl -lne'
  print /(\d+)$/ and $t += $1;
    print $t if eof
    ' filename


Last edited by radoulov; 09-08-2008 at 07:17 PM..
# 7  
Old 09-08-2008
Shell

Thanks for the perl.

Can somebody help me using Shell.
 
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

How to print elements between letters bash script?

Hello to all, May somebody help me to fix my bash code below, I'd like to do it only using loops and if statements is possible. I the content of the arrays are represented by the following 2 strings, where each character is an element inside the array. String for case 1:... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

3. Shell Programming and Scripting

[Solved] Search for a word and print the next word

Hi, I am trying to search for a word and print the next word. For example: My text is "<TRANSFORMATION TYPE ="Lookup Procedure">" I am searching for "TYPE" and trying to print ="Lookup Procedure" I have written a code like following: echo $line | nawk... (4 Replies)
Discussion started by: sampoorna
4 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. Shell Programming and Scripting

How ti Grep for a word and print the next word

Hi can we grep for a word and print the next word of the greped word? ex:- create or replace function function_name create function function_name we should search for word "function" and output next word "function_name" from both lines. (3 Replies)
Discussion started by: manasa_vs
3 Replies

6. UNIX for Dummies Questions & Answers

Grep /Awk letters X - X in every line and print it as a mac address

hey i m kinda new to this so i will appreciate any help , i have this list of values: pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200 pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300 pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies

7. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

8. 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

9. Shell Programming and Scripting

Choose a single word from a wordlist by matching the letters it contains?

Hi, I have a text file with 1500 words. Could it be a script that will keep the words that only have all these letters: n i o m s c t a If you could show me the way I would be greatful! (32 Replies)
Discussion started by: hakermania
32 Replies

10. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies
Login or Register to Ask a Question