LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02:14 AM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

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, 03:07 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 03:11 AM   #3
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

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


Reply



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 02: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 10:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

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

All times are GMT -5. The time now is 06:43 AM.

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