Unix programming scripts.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix programming scripts.
# 1  
Old 03-06-2007
Unix programming scripts.

How can I replace "?" with the appropriate information.
# 2  
Old 03-06-2007
Using sed

Actual File:
cat /tmp/question
What is the correct answer??
Replace th?s
??
Hello Boss? ???
?? hell ??

This is substitue ' ! ' in all occurrences of ' ? '.
sed 's/?/!/g' /tmp/question

After replacement:
What is the correct answer!!
Replace th!s
!!
Hello Boss! !!!
!! hell !!

Please let us know if this works..

Thanks
Nagaraj G
# 3  
Old 03-07-2007
in Perl:
Code:
$ perl -pi -e 's/\?/!/g' filename

replace all occurances of ? with ! in filename
# 4  
Old 03-07-2007
an alternate way with awk could be:

Code:
echo "HELLO? HOW ARE YOU?" | awk '{ gsub(/\?/, "\|");     print $0; }'

output:

Quote:
HELLO| HOW ARE YOU|
# 5  
Old 03-07-2007
Hi ennstate,

from you thread:

sed 's/?/!/g' /tmp/question

can you explain what mean "s" and "g" and thereis any other alphabet that using in sed command?
thank you



Regards,


heru
# 6  
Old 03-07-2007
Thank you for your answer guys, I really appreciate it.
# 7  
Old 03-07-2007
Quote:
Originally Posted by heru_90
Hi ennstate,

from you thread:

sed 's/?/!/g' /tmp/question

can you explain what mean "s" and "g" and thereis any other alphabet that using in sed command?
s is search and replace; g is global, i.e., replace all occurrences of the search pattern instead of only replacing the first.

There are many other commands; read the man page for more information, or go to one of the on-line resources listed on my shell links page: http://cfaj.freeshell.org/shell/resources.shtml
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

2. Shell Programming and Scripting

Unix programming help

hey guys im trying to create a batch file that makes directories i have this code atm #!/bin/sh echo "Please enter file name:" read Filename echo "enter number of files to be created " read created for (( i = 1; i < &created; 1++ )) do mkdir $Filename$i done assume i enter... (7 Replies)
Discussion started by: josh111
7 Replies

3. Programming

Need help in Unix C programming

hey guys. im currently trying to make a program in unix (redhat, compiling the .c file using gcc) and i need urgent urgent help. i need to save objects of structures in a file but they dont seem to be saving properly. ive been on it for a whole day now. dunno why i cant do it. when i try to... (4 Replies)
Discussion started by: mjumrani
4 Replies

4. UNIX for Dummies Questions & Answers

C Programming in Unix

I asked this over on the "High Level Programming Section" but there must be a secret handshake or something that I am missing.....anyway....if a person wanted to start some C programming in UNIX what would be the best compiler to start with ?? I am fairly familiar with visual studio and have done... (2 Replies)
Discussion started by: zapper222
2 Replies

5. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

6. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies

7. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies

8. UNIX for Dummies Questions & Answers

programming on unix

can someone tell me some programming commands on unix? (2 Replies)
Discussion started by: fretis
2 Replies

9. UNIX for Advanced & Expert Users

Porting of Windows written unix scripts to unix platform

Can anybody help me in finding out a solution for the problem below? When we write .unix or .sh files in windows OS and port them to Unix platforms there is a character ^M inserted at the end of each line of the script file. During ftp porting I set the transfer mode as ASCII for the script... (7 Replies)
Discussion started by: tamilselvi
7 Replies
Login or Register to Ask a Question