Another sed thread


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Another sed thread
# 1  
Old 12-17-2010
Another sed thread

Hi guys.

Im trying to access variables through sed, however none of the answers I've seen on the forums has worked for me. (All kind of quotes) Or maybe Im just placing them in a wrong place or something. Anyway, I tried many options before actually posting.

Here's my code
Code:
COUNT="1
2
3
4
5
6
7
8
9
10"
for i in `/usr/bin/echo ${COUNT}`
    do
    /usr/local/bin/grep Sent ${somePath}/${somePath2} | /usr/local/bin/grep "from:2121" | /usr/local/bin/egrep -i "Thanks..file $i" | wc -l >> votedFile.csv 
done

*Up to this part works fine*

Now I need to add some characters at the beginning of each line of that file I just created:
Code:
/usr/bin/cat votedFile.csv | sed "s/^/Voted for file $i/" > votaronFoto2.csv

This doesnt work. And I believe I've tried with many combinations of quotes already.

I get for all combinations 'Voted for file 10' *correctValueHere*

Thanks for your help

Last edited by illTry; 12-17-2010 at 06:35 PM..
# 2  
Old 12-17-2010
Try
Code:
/usr/bin/cat votedFile.csv | sed "s/^\(.*\)$/Voted for file ${j} \1/" > votaronFoto2.csv

Code:
sed "s/^\(.*\)$/Voted for file ${j} \1/" votedFile.csv > votaronFoto2.csv

OR
Code:
 
/usr/bin/cat votedFile.csv | sed "s/.*/Voted for file ${j} &/" > votaronFoto2.csv

Code:
 
sed "s/.*/Voted for file ${j} &/" votedFile.csv > votaronFoto2.csv

# 3  
Old 12-17-2010
First, thanks for the quick response anurag.singh, however all of those options give me that pesky '10', instead of 1,2,3..... Smilie
# 4  
Old 12-17-2010
what exactly is j here. what is it's value.
Please post few input file data and expected output.
To me it looks like j is actually count which varies from 1-10 and if so, then we need to put sed command inside for loop
and use i variable (instead of j) to get values from 1 to 10.
# 5  
Old 12-17-2010
Thanks a lot anurag.singh, here's current info:
Code:
CONTADOR="1
2
3
4
5
6
7
8
9
10"
for i in `/usr/bin/echo ${CONTADOR}`
do
    /usr/local/bin/grep Sent ${HOMELOG}/${ACCESSLOG} | /usr/local/bin/grep "from:2121" | /usr/local/bin/egrep -i "Gracias por votar por la foto $i" | wc -l >> votaronFoto.csv

    sed "s/.*/Voted for file ${i} &/" votaronFoto.csv > votaronFoto2.csv
done

Expected Result:
Code:
Gracias por votar por la foto 1 *numberOfHits*
Gracias por votar por la foto 2 *numberOfHits*
Gracias por votar por la foto 3 *numberOfHits*
Gracias por votar por la foto 4 *numberOfHits*
Gracias por votar por la foto 5 *numberOfHits*

Current Result:
Code:
Gracias por votar por la foto 10 *numberOfHits*
Gracias por votar por la foto 10 *numberOfHits*
Gracias por votar por la foto 10 *numberOfHits*
Gracias por votar por la foto 10 *numberOfHits*
Gracias por votar por la foto 10 *numberOfHits*


Thanks again!!

Last edited by Franklin52; 12-18-2010 at 10:58 AM.. Reason: Please use code tags
# 6  
Old 12-17-2010
I guess current result you gave is from votaronFoto.csv file.
If it has all lines with value 10 means there was no record with values 1-9 as outcome of egrep and you result came for 10.
To confirm this, you may do some kind of debgging like run only for CONTADOR value 1 OR only for 2 OR may be for 1-9 and see if you get any record in votaronFoto.csv.
OR for debugging purpose, you may created different file for each count.
Code:
/usr/local/bin/grep Sent ${HOMELOG}/${ACCESSLOG} | /usr/local/bin/grep "from:2121" | /usr/local/bin/egrep -i "Gracias por votar por la foto $i" | wc -l >> votaronFoto$i.csv

And see if you get some records in all files.
I'm just suggesting some ways to check why votaronFoto.csv has records only for value 10.

File votaronFoto2.csv should have "Voted for file 10" at the start of every line.
# 7  
Old 12-17-2010
This is the outcome for votaronFoto.csv
Code:
       6
       5
       1
       0
       1
       0
       1
       0
       1
       0


This is the full outcome of file votaronFoto2.csv
Code:
Voted for file 10        6
Voted for file 10        5
Voted for file 10        1
Voted for file 10        0
Voted for file 10        1
Voted for file 10        0
Voted for file 10        1
Voted for file 10        0
Voted for file 10        1
Voted for file 10        0

So first file is working ok.
I dont get why is not taking the same value $i for the second file as it did work for the first line. Smilie

Last edited by Franklin52; 12-18-2010 at 10:58 AM.. Reason: Please use code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

2. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

3. Programming

Parent Thread Of Child Thread

Parent Thread Of Child Thread Suppose a process creates some threads say threadC and threadD. Later on each of these threads create new child threads say threadC1, threadC2, threadC3 etc. So a tree of threads will get created. Is there any way to find out the parent thread of one such... (1 Reply)
Discussion started by: rupeshkp728
1 Replies

4. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies
Login or Register to Ask a Question