Register
It is currently Mon Oct 20, 2014 7:04 am

Echo at the end of previous line


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sun Aug 17, 2014 3:37 am   

Joined: Fri Jun 27, 2014 2:04 am
Posts: 6
Hello!
I have next script and stuck at one position

Code:
cat $line > data.txt
echo $line
grep -e 'something1:' -e 'something2' -e 'something3' data.txt >> fields.txt
echo -en "," >> fields.txt
grep -e 'No match for' data.txt >> fields.txt
grep -e 'anything1:' -e 'anything2:' -e 'anything3:' data.txt >> fields.txt
echo '|' >> fields.txt


Now it proceed an output like here
Code:
something1
,anything2
|
something2
,anything1
|


I want minimize manual work and format string like this
Code:
something1,anything2
|
something2,anything1
|
No match for
|

I think i need to put a comma at the end of first grep. I tried to put "\b" in echo - but it does not work
Thanks


Top
 Profile  
 PostPosted: Sun Aug 17, 2014 9:37 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
try something like...

Code:
cat $line > data.txt
echo $line
$var1=`grep -e 'something1:' -e 'something2' -e 'something3' data.txt`
echo -n "$var1" >> fields.txt
echo -en "," >> fields.txt
grep -e 'No match for' data.txt >> fields.txt
$var2=`grep -e 'anything1:' -e 'anything2:' -e 'anything3:' data.txt`
echo $var2 >> fields.txt
echo '|' >> fields.txt


Top
 Profile WWW  
 PostPosted: Sun Aug 17, 2014 3:14 pm   

Joined: Fri Jun 27, 2014 2:04 am
Posts: 6
./script.sh: line 3: =: command not found
./script.sh: line 7: =: command not found

It seems it cannot assign command output to $var1 and $var2
I tried without $, put a spaces around "=", put commands in different quotation marks, but no luck :(


Top
 Profile  
 PostPosted: Sun Aug 17, 2014 3:40 pm   

Joined: Fri Jun 27, 2014 2:04 am
Posts: 6
Thanks.
I do it!
var1=$()
echo $var1

But now (i did not describe above) cat reads only first line and script is stopped

here is full script
Code:
#!/bin/bash
while read line
do
cat $line > data.txt
echo $line
var1=$(grep -e 'something1:' -e 'something2' -e 'something3:' data.txt)
echo -n "$var1" >> fields.txt
echo -en "," >> fields.txt
grep -e 'Glam' >> fields.txt
grep -e 'No match for' data.txt >> fields.txt
var2=$(grep -e 'anything1:' -e 'anything2:' -e 'anything3:' data.txt)
echo $var2 >> fields.txt
echo '|' >> fields.txt
sed -i s/'apy1:'/''/g fields.txt
sed -i s/'bpt5:'/''/g fields.txt
sed -i s/'bla3:'/''/g fields.txt
sed -i s/'bls2:'/''/g fields.txt
sed -i s/'bls3:'/''/g fields.txt
sed -i s/'^\ '/''/g fields.txt
sed -i s/'                '/''/g fields.txt
sleep 4
#sleep $[ ( $RANDOM % 10 )  + 1 ]s
cat data.txt >> full.txt
echo --- >> full.txt
done
sed -i s/' '/,/ fields.txt


list of input data contain just 500 lines of text
usage ./script.sh < linedata.txt


Top
 Profile  
 PostPosted: Tue Aug 19, 2014 6:07 pm   

Joined: Fri Jun 27, 2014 2:04 am
Posts: 6
And i find a solution :)
rs -e -C, 1

Sergey@Ubunru:~/whatis rs
rs (1) - reshape a data array
I've added a pipe to grep results with rs - and it insert a comma at the end of each line


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP