sed command usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command usage
# 1  
Old 03-06-2013
sed command usage

Hi,

Can anyone let me know the sed command usage

requirement:

Code:
sed 's/standard/standard_and/' <new.txt>new.txt

here it needs to search for the pattern "standard" in the file new.txt and it should replace as "standard_and" in the same file new.txt
Note: new.txt is having a separator '|'

Can anyone say me the correct command here

Thank you!

Last edited by Scrutinizer; 03-06-2013 at 03:29 AM.. Reason: code tags
# 2  
Old 03-06-2013
When u use the same file name, then the resulting file will be a zero byte.

Try sed 's/standard/standard_and/g' new.txt > new1.txt
# 3  
Old 03-06-2013
Quote:
Originally Posted by srikanth_sagi

sed 's/standard/standard_and/' <new.txt>new.txt
It is never advisable to write your code output directly to your file.

better way is

Code:
sed 's/standard/standard_and/' <new.txt > temp_file
mv temp_file new.txt

Or use -i option from sed.

Regards,

pamu
# 4  
Old 03-06-2013
Hi,

Thanks for the update!

But i need to modify the columnname from "standard" to "standardand" in the flat file before it is FTPied to a particular location.

a filename with directory location is stored in a unix variable, i need to modify that before ftping
example
Code:
$direcorylocation/$filename

so i need to do
Code:
sed 's/standard/standardand/' < $direcorylocation/$filename

- iam not sure what to do here

This is an automated process and i cannot modify in the middle

Last edited by Scrutinizer; 03-06-2013 at 03:30 AM.. Reason: code tags
# 5  
Old 03-06-2013
Code:
sed 's/standard/standardand/' < $direcorylocation/$filename > tempfile

Then run ftp or whatever on tempfile

Last edited by Scrutinizer; 03-06-2013 at 03:30 AM.. Reason: code tags
# 6  
Old 03-06-2013
Hi,

I cannot run ftp on the tempfile, i can run only on $direcorylocation/$filename - this value is predefined.
# 7  
Old 03-06-2013
add a command after the replacement,

Code:
mv tempfile $direcorylocation/$filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed command usage question

How to work x in sed command? I know x command is swaps the contents of pattern space and hold space. But i am unable to understand it's working? (4 Replies)
Discussion started by: Vartika18
4 Replies

2. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

3. Shell Programming and Scripting

sed usage

Hi, I want to replace some character whenever there is a space using sed. Input file name: aaa command i am trying is sed 's/^$/A/g' aaa (2 Replies)
Discussion started by: rakeshbharadwaj
2 Replies

4. Shell Programming and Scripting

sed usage

Hi, I want to read a command value and replace the command value in another file. Anybody know how to write it??? For example: File A: Command1 = test File B: Command1 = Command2 = Command3 = I want to write a shell script to read content from File A and replace Command1... (3 Replies)
Discussion started by: linboco
3 Replies

5. Shell Programming and Scripting

Sed usage

How can i use sed to change "Linux Cpu (EDF).sh" to "LinuxCpuEDF.sh"? I want to replace the spaces and brackets. (4 Replies)
Discussion started by: proactiveaditya
4 Replies

6. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

7. Shell Programming and Scripting

sed usage

I'd like to extract the temps from the following command via a series of sed statements but the actual syntax is beyond me. $ nc localhost 7634 ... (2 Replies)
Discussion started by: audiophile
2 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. Shell Programming and Scripting

possible sed usage

Sorry about the title. I'm assuming I want sed anyway... Here's the deal: I have hundreds of files in a folder and they all are named with the same format. $NAME-$VERSION-$ARCH-$BUILD This is Slackwares' /var/log/packages directory BTW... $BUILD is what I'm focusing on. It could be... (6 Replies)
Discussion started by: madpenguin
6 Replies

10. Linux

sed usage

Hi , I have a question. How do I replace 2 words in one line like this IN CLO07 INDEX IN CLOIX07 to IN CLO07_S02 INDEX IN CLOIX07_S02 But one thing to remember is that there are lots of words like CLODM001 . So the only matching pattern is "IN CLO" sample file... (4 Replies)
Discussion started by: capri_drm
4 Replies
Login or Register to Ask a Question