You are not logged in.

#1 2012-10-14 22:17:21

moofly
Member
Registered: 2012-09-01
Posts: 11

script works on a test file but not on the non-test file

here is the code

#!/bin/bash

file='/mnt/files/mysecondhome/Upkeep/Arch.Upkeep/Music/play3'
cat ${file} | \
while read name num 
do
sum=$(($num + 1))
sed s/"$name $num/$name $sum"/g /mnt/files/mysecondhome/Upkeep/Arch.Upkeep/Music/playcount1 > /home/ryan/Upkeep/Music/play2
done  

I took a sample from the non-test files and put it in the test files, and it works. I'm not really sure what to do now, thanks in advance for your help.

Offline

#2 2012-10-14 22:40:42

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: script works on a test file but not on the non-test file

What are these files supposed to be?

You're constantly overwriting /home/ryan/Upkeep/Music/play2 with the single > redirect so only the last loop counts.

You probably want to copy playcount1 and then use sed -i on it.

Last edited by Procyon (2012-10-14 22:41:05)

Offline

#3 2012-10-14 22:44:58

moofly
Member
Registered: 2012-09-01
Posts: 11

Re: script works on a test file but not on the non-test file

right now i don't have it on a cron job since it doesn't work. once it works i was planning on moving play2 to playcount1
sample of playcount1 since its 930k:

ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWallsYYYYYJJJJJfYYYYYJerichoZZZZZWithYYYYYDevilsYYYYYAmongstYYYYYUsYYYYYAllZZZZZWelcomeYYYYYHomeXXXXXmpCCCCC 0
ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWallsYYYYYJJJJJfYYYYYJerichoZZZZZWithYYYYYDevilsYYYYYAmongstYYYYYUsYYYYYAllZZZZZWithYYYYYDevilsYYYYYAmongstYYYYYUsYYYYYAllXXXXXmpCCCCC 0
ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWarZZZZZWhyYYYYYCan'tYYYYYWeYYYYYBeYYYYYFriendsVVVVVZZZZZLowYYYYYRiderXXXXXmpCCCCC 1
ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWarpstoneZZZZZDaemonicYYYYYWarpfireZZZZZAYYYYYStrangeYYYYYWindYYYYYIsYYYYYWaillingYYYYYForYYYYYTheYYYYYDeadXXXXXmpCCCCC 0
ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWarpstoneZZZZZDaemonicYYYYYWarpfireZZZZZBloodYYYYYPaintedYYYYYMountainXXXXXmpCCCCC 0

play3:

ZZZZZmntZZZZZfilesZZZZZmysecondhomeZZZZZMusicZZZZZWarZZZZZWhyYYYYYCan'tYYYYYWeYYYYYBeYYYYYFriendsVVVVVZZZZZLowYYYYYRiderXXXXXmpCCCCC 1

i wasn't sure if certain special caracters or numbers were messing it up so thats whats with the zs ys vs xs and cs. also -i doesn't help

Last edited by moofly (2012-10-14 22:58:00)

Offline

#4 2012-10-15 11:45:02

Tes--
Member
Registered: 2009-11-13
Posts: 42

Re: script works on a test file but not on the non-test file

Are you trying to increase the count of all files with 1?

If so, you could use awk:

#!/bin/bash
file='/mnt/files/mysecondhome/Upkeep/Arch.Upkeep/Music/play3'
awk '{ print $1, $2+1 }' "$file" > /home/ryan/Upkeep/Music/play2

Offline

#5 2012-10-17 18:28:53

bsilbaugh
Member
From: Maryland, USA
Registered: 2011-11-15
Posts: 141

Re: script works on a test file but not on the non-test file

@moofly, your post does not specify what it is that you are trying to do. Therefore, at best, others can only tell you what your script does, and even this require some assumptions on the properties of the files you are trying to operate on.

I suggest that you clearly specify what it is you are trying to do. Also, you say that your script doesn't work on the non-test files. What do you mean by this? In what sense does your script fail? For example, does it generate garbage output? Does it fail to do anything? What happens?


- Good judgement comes from experience; experience comes from bad judgement. -- Mark Twain
- There's a remedy for everything but death. -- The wise fool, Sancho Panza
- The purpose of a system is what it does. -- Anthony Stafford Beer

Offline

Board footer

Powered by FluxBB