changing last 2 digits of text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting changing last 2 digits of text
# 1  
Old 11-07-2006
changing last 2 digits of text

I have a text file with a bunch of ethernet port names and host names. I need to just change the last 2 chars on each line to a new number how can I do this quickly?

from

ethernet5/35 Net01
ethernet5/36 Net01
ethernet5/37 Net01
ethernet5/38 Net01

to

ethernet5/35 Net02
ethernet5/36 Net02
ethernet5/37 Net02
ethernet5/38 Net02

This is I have like 25 switches that all have same ports I need to work with and doing it manually will be killer. Can I do this in vi or some awk command? To be honest it can even dump it back into the same file right under old stuff.
# 2  
Old 11-07-2006
Code:
sed 's/Net01$/Net02/'  somefile > tmpfile
mv tmpfile somefile

# 3  
Old 11-07-2006
thanks that will work also i wanna combine them to one file im trying paste and join and its just not appending it to the end its combining them side by side. how can I just add file 1 to the bottom of file 2?
# 4  
Old 11-07-2006
Code:
cat file1 > tmpfile
sed 's/Net01$/Net02/'  file2 >> tmpfile
mv tmpfile file1

# 5  
Old 11-07-2006
Thanks dude!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

3. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

4. Shell Programming and Scripting

Changing a text file

I have a file as below and want to change it using awk I want to find the entries such as Iteration No.788 Best Value 0.00408152 Next-Worst Value 0.00522935 Worst Value 0.00523487 and change it to Iteration No.788 788. Best Value = 0.00408152 788. ... (8 Replies)
Discussion started by: kristinu
8 Replies

5. Programming

changing text color in c

I'm writing my own Unix ls command in c and I was wondering if anyone knows how to or can point me to a tutorial that shows me how to change the text color of the filename depending on if it's a directory, regular file, linked file, etc..., like the real ls command does? Thanks. (4 Replies)
Discussion started by: snag49ers
4 Replies

6. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

7. Shell Programming and Scripting

changing text

i all, I thought I would restructure my question. Is there a way you can get rid of characters in a line if you know what number they are. eg, if this was a line you could see there were 18 characters including spaces. Could I delete characters 4,5,6 and 7 to remove the word this. ... (2 Replies)
Discussion started by: outthere_3
2 Replies

8. UNIX for Advanced & Expert Users

Changing Text Color Using VT100

Hi, I want to change the color of the text. Currently, I am using the following VT100 command, which changes the color of the foreground: <ESC>[{attr1};...;{attrn}m The problem is, when I change the color of the foreground, it changes the color of the text as expected, but it also... (4 Replies)
Discussion started by: Abed Alnaif
4 Replies

9. Shell Programming and Scripting

changing size of text at xterm

hi all, i log into an xterm with bash shell but the character size of the xterm shell is too small. how can i enlarge the size of text on this xterm bash shell? (3 Replies)
Discussion started by: armen
3 Replies

10. UNIX for Dummies Questions & Answers

Changing text with sed?

Hi everyone, Having trouble with sed. I searched the board and found some stuff, but still unclear. I have a file named "userfile" which stores the users info in this form: email:username:password: I want the user to be able to change their password. i tried with sed s/oldpass/newpass/g... (2 Replies)
Discussion started by: primal
2 Replies
Login or Register to Ask a Question