LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-07-2010, 05:36 AM   #1
StaneASDASD
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Shell script to -10 to a text file


Ok, not the best title...

I have this small text file my music player uses to state current data.
looks like this
"
audio_device_state:1:Sound Card
state: play
current: 0
time: 596
random: 0
repeat: 0
single: 0
consume: 0
crossfade: 0
playlist_begin
0:Voyage of the Beagle
...
"

I need a tiny script to change the "time: A" part to "time: A-10", in other words I want script to remove 10 from the time value.So my player with start playing 10seconds earlier in the file. How can I do this? sed? awk? grep?

Last edited by StaneASDASD; 10-07-2010 at 05:37 AM.
 
Old 10-07-2010, 05:55 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

try this:
Code:
awk '($1 == "time:"){$2 -= 10}{print $0}' filename > newfile
 
Old 10-07-2010, 06:06 AM   #3
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Code:
 ruby -i -F": " -ane '$F[1]=$F[1].to_i-10 if $F[0]["time"];puts $F.join(": ")' file
 
Old 10-07-2010, 06:15 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk '$1~/time/{$2-=10}1' file
 
  


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
shell script to read a certain segment of a text file? recomboDNA Programming 3 06-16-2010 01:57 AM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
how to convert a text file into shell script meng_en Linux - General 9 10-15-2002 10:46 PM

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

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