LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2011, 06:43 AM   #1
amitverma4587
LQ Newbie
 
Registered: Jun 2011
Posts: 1

Rep: Reputation: Disabled
unable to store multiple sed operations using pipe in a variable


I am not able to execute a multiple sed statement using pipe filters in a variable. i am trying to extract a path from a file and then working on that path to change a few letters within the path by going through another sed statement.

the code looks like this:

Quote:
for i in 1 2 3 4 5 6 7
do
for j in F E I D
do
cpath="`sed -n "11,11p" <path.cfg | sed -n 's/voicex/voice'$i'/g; s/voicecolx/voicecol'$i'/g; s/" F "/" '$j' "/g;P'`"
echo $cpath
more $cpath 2>error.log | grep " '&j' " | wc -l | echo "The count of '$j' in file is: " `wc -l` 1>countdir/count$j.txt
done
done
i saved this file in stest.sh. When i run the file, nothing happens. I ahve to press Ctrl+C to exit back to the command prompt.

Let me also provide the path.cfg file:

Quote:
MPAY
/var/xacct_data/xxxx/log_flattener/xxxx/logfile_current

FAFF
/var/xacct_data/faff/faff1/log_flattener/faffsnp1/ logfile_current
/var/xacct_data/faff/faff1/log_flattener/faffdbt1 /logfile_current
/var/xacct_data/faff/faff1/log_flattener/fafftxn1 /logfile_current
/var/xacct_data/faff/faff2/log_flattener/faffdbt2/ logfile_current

VOICE
/var/xacct_data/voice/voicex/log_flattener/ voicecolx/logfile_current
/var/xacct_data/voice/voicex/log_flattener/ voiceprox/logfile_current
/var/xacct_data/voice/voicex/log_flattener/ voicedisx/logfile_current

GPRS
/var/xacct_data/gprs/gprsx/log_flattener/gprscolx/logfile_current
/var/xacct_data/gprs/gprsx/log_flattener/gprsprox/logfile_current
/var/xacct_data/gprs/gprsx/log_flattener/gprsdisx/logfile_current

IPC
/var/xacct_data/ipc/ipcx/log_flattener/ipccolx/logfile_current
/var/xacct_data/ipc/ipcx/log_flattener/ipcprox/logfile_current
/var/xacct_data/ipc/ipcx/log_flattener/ipcdisx/logfile_current

SMS
/var/xacct_data/smsc/smscx/log_flattener/smsccolx/logfile_current
/var/xacct_data/smsc/smscx/log_flattener/smscprox/logfile_current
/var/xacct_data/smsc/smscx/log_flattener/smscdisx/logfile_current
 
Old 06-02-2011, 10:12 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Well, your immediate problem is that echo is not a command that can accept input from stdin, so you can't use it in the middle of a pipe chain like that. Oh, and there's an embedded wc command without any input following that echo.


I see a couple of other errors and weak points, such as the "&j" in grep (I think you want "$j"), that you could probably combine the two sed commands into one, and that $(..) is highly recommended over `..`. Also, your code would be much easier to read and debug if you'd use a decent indentation scheme*. But I'm too tired right now to go into any more detail.


*Edit: I just noticed you're using quote tags instead of the proper [code][/code] tags. quote tags don't preserve formatting the way code tags do. So apologies if your code originally had indentations.

Last edited by David the H.; 06-02-2011 at 10:17 AM.
 
Old 06-02-2011, 10:58 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would add to David's post and say if you also provide the desired output from your chosen input that it may help someone see where we may be able to help?
 
  


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
Pipe a variable using grep in a script. okos Linux - Software 6 08-17-2009 02:31 AM
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 03:44 PM
combining multiple sed operations into a single command kushalkoolwal Programming 3 09-16-2008 05:58 PM
[SOLVED] working on files with sed and pipe angel115 Linux - Newbie 4 10-23-2005 06:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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