LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-11-2010, 03:14 AM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,031

Rep: Reputation: 47
grep gurus, I need your help


I'd like to edit txt file so that these lines:
p2snmpmod HDRx_05 address="10.20.30.40" subslo=5 slonum=0
p2snmpmod HDRx_06 address="10.20.30.40" subslo=6 slonum=0
p2snmpmod HDRx_07 address="10.20.30.40" subslo=7 slonum=0
..

become like this:
p2snmpmod HDRx_01 address="10.20.30.40" subslo=5 slonum=0
p2snmpmod HDRx_02 address="10.20.30.40" subslo=6 slonum=0
p2snmpmod HDRx_03 address="10.20.30.40" subslo=7 slonum=0
..

I'd do it manually but there is a lot of them, and I might need something similar again.
please help me out.

thanks.
 
Old 11-11-2010, 04:07 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Do you mean to renumber the second field starting from 1? Awk can easily do that, e.g.
Code:
awk '/^p2snmpmod/{sub(/_[0-9]+/,sprintf("_%02d",++count),$2); print}' file
but it strongly depends on the exact format of the whole file. Does the numbers exceed 99? Is the first field always "p2snmpmod"? Just to give you an idea.
 
1 members found this post helpful.
Old 11-11-2010, 04:11 AM   #3
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,031

Original Poster
Rep: Reputation: 47
thank you very much;
no, all numbers are <50;
yes it always starts with p2snmpmod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Grep -p for Linux, Trying to grep a paragraph. ohijames Linux - Newbie 5 07-22-2010 03:09 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 08:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration