Command line ok but not shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Command line ok but not shell
# 1  
Old 04-08-2010
Command line ok but not shell

I want to substitute a charactor "PAN" with "TAN" in a shell, I used sed command in shell, it wo'nt work but the same is run from command prompt it was successful. the command is

sed ' s/PAN/TAN/g ' <i/p> > <o/p>
sed ' s/^M/^M/g ' <i/p> > <o/p> (1st ^M is Ctrl+V+M, 2nd should be line feed/next line)

the same problem is with delete option in sed

Please suggest



actually file consist of single line with multiple ^M character, i am trying to convert all ^M character into line feed i.e new line (so that single line file become multiple line sequential file), the same works from command line but not from shell program.

thanks
# 2  
Old 04-08-2010
Try specifying the full path of sed in your shell script
# 3  
Old 04-08-2010
Quote:
sed ' s/PAN/TAN/g ' <i/p> > <o/p>
sed ' s/^M/^M/g ' <i/p> > <o/p> (1st ^M is Ctrl+V+M, 2nd should be line feed/next line)
There are errors in the samples posted which would perhaps be more visible if the lines were posted in code tags.
1) There is no "output filename" parameter to "sed". See "man sed".
2) There are excess space characters in the commands posted.

Code:
First command should probably be:
sed -e "s/PAN/TAN/g" input_filename > output_filename

Second command.
I have never been able to make this conversion work with "sed".
Part of the problem is that "sed" does not recognise a line at all unless it ends with a line-feed character.
If you just want to convert carriage-return to line-feed, use the unix translate command "tr".

cat input_filename | tr '[\r]' '[\n]' > output_filename

Most of these carriage-return issues arise when a text file is created on a M$ platform and the copied to a
unix platform using a file transfer method which does not convert the file (e.g. binary mode ftp).
The normal repair involves running unix command "dos2unix" or "dos2ux" to convert the text file.
When foreign character sets are involved it can be better to convert the file with "tr" or an "awk" program.

Last edited by methyl; 04-08-2010 at 08:01 PM.. Reason: layout
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls -1 at Command Line vs in a Shell Script

Hello, I have symbolic links to a bunch of directories (all starting with the letter X) in the cwd. When I run the following on the command line, I get the list as I want it. ls -1 X* > dir.list However when I run it in a shell script like given below, it lists all the files in each of... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. Shell Programming and Scripting

Use shell variable in perl command line

Hi, I would like to use a shell variable $amp in my perl command line. for fa in $WORKSPACE/*.fa; do amp=`grep ">.*" $fa | sed -e's#>\(.*\)#\1#g'` ampsam="$WORKSPACE/$base/$base.$amp.sam" sqheader=`grep "^@SQ.*SN:$amp.*" $sam` printf "$sqheader\n" >> $ampsam ... (3 Replies)
Discussion started by: jdilts
3 Replies

3. UNIX for Dummies Questions & Answers

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies

4. Shell Programming and Scripting

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies

5. Shell Programming and Scripting

Embeded shell variable in command line

Hello, I know this is a situation about the single quote and double literal, but I could not figure out after many search. I need to loop through thousands of different BACs sequencing to optimize kmer individually. IN=/PATH/TO/INPUT/FILES for sample in S{01..1096} do run_program... (9 Replies)
Discussion started by: yifangt
9 Replies

6. Shell Programming and Scripting

Any shell or hack that makes the shell command line take vi commands?

basically i'm tired of hitting the left arrow a few dozen times when correcting a mistake or modifying a history command i'd like to use vim style key shortcuts while on the command line so that a 55 moves the cursor 55 places to the left... and i want all the other vi goodies, search of... (3 Replies)
Discussion started by: marqul
3 Replies

7. Shell Programming and Scripting

How to use case and command line arguments in shell script?

Hi... can anyone please help me out in using the CASE and command line argument in shell script... i am bit new to shell scripting...below i have explained my proble with example... say i have an executable file with name 'new1.sh' and there are 3 functions in it a(), b() and c()....and there... (5 Replies)
Discussion started by: swap21783
5 Replies

8. Shell Programming and Scripting

Shell script command line arguments

Hello All, i am known to the limitation of different shells while passing more than 9 command line arguments i just tried the example below i do see my current shell is tcsh echo $SHELL /bin/tcsh so if i make my script executable and run it output is ... (6 Replies)
Discussion started by: Deepak Dutt
6 Replies

9. UNIX for Dummies Questions & Answers

Passing command line argument between shell's

Hi, I am facing a problem to pass command line arguments that looks like <script name> aa bb "cc" dd "ee" I want to pass all 5 elements include the " (brackets). when I print the @ARGV the " disappear. I hope I explain myself Regards, Ziv (4 Replies)
Discussion started by: zivsegal
4 Replies

10. UNIX for Advanced & Expert Users

use email subject line as shell command

If anyone can give me some ideas on this it would be great. What I'm trying to do is to have emails be sent to my unix account. Once they are emailed to the unix account, I want to use the text in the subject field to invoke a shell script, so basically I need to find a way that I can... (4 Replies)
Discussion started by: mskarica
4 Replies
Login or Register to Ask a Question