LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2013, 12:35 AM   #1
nicksu
Member
 
Registered: Dec 2012
Posts: 35

Rep: Reputation: Disabled
sed fill form


Hi,I have a CSV form to fill in,but when I use sed,it will cover or append the output line.can anyone help to solve it ?sed 'w file' or sed > file would also cover the lines which output before
 
Old 03-29-2013, 01:07 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Let's know your sample CSV form and commands that you've tried so far.
 
Old 03-29-2013, 01:57 AM   #3
nicksu
Member
 
Registered: Dec 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
hi,a -i work
 
Old 03-29-2013, 08:30 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
It appears that he's talking about how redirecting the output back into the same file will overwrite it.

This is true of all redirections, whatever the program. The ">" is processed and the file truncated before the command is ever run, so naturally you'll end up with an empty file. You almost always have to output to a different temporary file and then replace the original with it.

gnu sed has added the '-i' option, which overwrites the original, but in actuality it just directs the output to a background temp file first anyway. Also, it's not portable since other versions of the program don't have it.

If you want to do true text editing without working with tempfiles, then try using ed instead. It's an actual text editor; it loads the entire file into a memory buffer for editing, and can thus write it back to the original safely. It's also often easier to use when doing multi-line editing.

How to use ed:
http://wiki.bash-hackers.org/howto/edit-ed
http://snap.nlc.dcccd.edu/learn/nlc/ed.html
(also read the info page)

There's also ex, which has a similar mode of operation and is even more powerful. On Linux it's actually a shell interface for vim.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How can I save my time not to do the same repetitive job in a webpage to fill a form pokhraa Linux - Software 2 12-24-2011 05:39 PM
auto fill a form and submit using curl limadario Linux - Software 1 06-04-2010 06:46 AM
bash/sed/awk fill each line in text file with space to fixed length khairil Programming 11 01-09-2008 06:28 AM
PHP: build query from form entry, then display results in the same form tonedeaf1969 Programming 4 06-22-2007 08:55 AM
how do I copy a whoel folder form one directory to another form the command line? zwyrbla Linux - Newbie 8 08-24-2004 07:40 PM


All times are GMT -5. The time now is 07:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration