LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-30-2006, 04:20 PM   #1
anchunlei
LQ Newbie
 
Registered: Nov 2003
Location: Bremen, DE
Distribution: Debian Etch/Lenny
Posts: 27

Rep: Reputation: 15
Emacs: conditional replace!!


Hi all, I have such a problem by using Emacs:
Here below are 2 columns of data,
1.5 Mbits
1.2 Mbits
234 Kbits
1.4 Mbits

I want to do a conditional replacement, which means "if the value of the 2nd column is 'Kbits', divide the corresponding value in the 1st column by 1000". In this case the 234 should be replaced by 0.234

I want to know how to do it with Emacs, or is there another way to realize it?

regards

anchunlei
 
Old 06-30-2006, 05:52 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I'm not proficient in lithp, but it would be quite easy in awk...


Code:
awk '{ if( $2 ~ /K/ ){ print $1/1000" Mbits" }else{print $1" Mbits"}}' snippet
 
Old 07-01-2006, 05:26 PM   #3
anchunlei
LQ Newbie
 
Registered: Nov 2003
Location: Bremen, DE
Distribution: Debian Etch/Lenny
Posts: 27

Original Poster
Rep: Reputation: 15
Thanks for the fast reply, I am learning awk now
 
  


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
Conditional Compilation oulevon Programming 3 02-26-2006 08:21 PM
CASE conditional la_mafia63 Linux - General 3 07-24-2005 01:02 PM
c compound conditional steve_96 Programming 9 06-04-2005 07:17 PM
Emacs search and replace neil Linux - Software 1 01-28-2005 06:04 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM

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

All times are GMT -5. The time now is 03:51 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