Single line file editing command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Single line file editing command?
# 1  
Old 04-03-2008
Question Single line file editing command?

Hello everyone. I have been reading a lot about the various different text editors at my disposal through Unix, but I just can't seem to close the deal for what I am trying to do. Is there a way to issue a single line command to edit a file where pattern=x, and do it non-destructively AND in-place? It is my understanding that sed does not do in-place edits, and I seem to be unable to use ed as a single-line command. Any help would be appreciated. Thank you.
# 2  
Old 04-03-2008
Not sure what kind of editing you want to do, but for simple find and replace, sed with the -i switch can perform that function in place.

sed -i.orig -e 's/pattern1/pattern2/g'

The -i.orig will make the change in the file and make a copy of the original file with the .orig extension in case you need to revert to the original file.

Hope this helps steer you in the right direction.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

2. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

3. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

4. Shell Programming and Scripting

Editing the first line of file

I have a sample file as below :- RECORD_COUNT|2660|28606946.86|20110701122349694| adkad|wwsgesg|mkmk|FFFF|FAFAF|FFAF|FAFFFFA|5894858| I have to replace the second coulmn in the first row which is the count of no of lines in the file from a new variable . Also I have to delete the 3rd... (2 Replies)
Discussion started by: Sanjeev Yadav
2 Replies

5. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

6. UNIX for Dummies Questions & Answers

single line command to delete a 6 months old file

i had this scenario where i need to delete a file that is 6 months old which is no longer needed. basically the filename is in the format of PCARDDAILYmmddyyyy.txt where the mm is the month, dd is the day, and yyyy is the year. e.g. PCARDDAILY05262009.txt PCARDDAILY05252009.txt ... (6 Replies)
Discussion started by: wtolentino
6 Replies

7. Shell Programming and Scripting

Editing last line of a file

Hi All, Could you please help me out with this problem? I need to edit the last line of my file. Ex: The last line in my file will be say 000056000045 8 I need to subtract some number from the number 45 and replace the new number in its place. ... (1 Reply)
Discussion started by: Anitha Chandran
1 Replies

8. UNIX for Advanced & Expert Users

Can't Editing File in Single mode (using vi)

Dear All, Yesterday I'm change /etc/vfstab file ( disable 1 Device mounting) and now I can't login to multiuser mode just single user mode, and now I want enable again, but I can't using vi editor in single user mode How to edit this file? thereis default can't using vi editor in single mode?... (14 Replies)
Discussion started by: heru_90
14 Replies

9. Shell Programming and Scripting

single line command

i need to search for a single pattern in three different logs....what would be the best one line script???? (4 Replies)
Discussion started by: roshanjain2
4 Replies

10. UNIX for Dummies Questions & Answers

editing bash command line with vi

Is there a way using bash that I can edit a command line using vi. I.e. if I have a long command line and I want to edit it.....by typing vi and then having the command open in an editing window.... I beleive this can be done in k shell by pressing v....however can find out how this can be... (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question