![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| to find header in Mp3 file and retrieve data | shashi | High Level Programming | 2 | 09-12-2008 04:03 AM |
| How to extract data from a huge file? | srsahu75 | Shell Programming and Scripting | 5 | 01-18-2008 05:06 AM |
| search and grab data from a huge file | ting123 | UNIX for Dummies Questions & Answers | 1 | 06-06-2006 10:41 PM |
| sed, insert data from a file to another? | ctcuser | Shell Programming and Scripting | 4 | 05-03-2005 02:43 PM |
| Insert a line as the first line into a very huge file | shriek | UNIX for Advanced & Expert Users | 3 | 03-09-2005 01:22 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract
if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and in its simplist form i could say echo 'H|PayerDataExtract' > ExtractDataFileWithHeader.dat cat ExtractDataFile.dat >> ExtractDataFileWithHeader.dat mv ExtractDataFileWithHeader.dat ExtractDataFile.dat but in all of the above an extra file is created. If i were to do this in vi manually the extra file could be avoided. Is there a way to avoid the extra file while still not having to manually use vi in a interactive manner? This is even more neccessary if the file uses over 50% filespace and an extra file will just double my usage , though temporarily |
|
||||
|
You can even use the sed 'insert' command along with -i (inline) option to place the the "header" at a specific line number (like line 1). Something like this should work: Code:
sed -i '1 i \Some Header Text Here' ExtractDataFile.dat |
|
||||
|
hi ddreggors/jim
i tried this - and it fails with the below error sed -i '1 i \HeaderText' ExtractDataFile.txt sed: illegal option -- i The system is a SunOS ussun1l 5.8 Generic_117350-60 sun4u sparc SUNW,Sun-Fire-15000 the perl option is out for me as the client may not want to install any piece of software without business cause, however as long as the tmp file is created in the /tmp space and not my file-dir i think i'm ok - any more ideas anyone? |
|
||||
|
try this: Code:
sed 1'i\HeaderText' ExtractDataFile.txt If this outputs to the screen as expected (this does not update the file) then the inner 'i' (insert command) is working fine. Next try: Code:
sed -i 1'i\HeaderText' ExtractDataFile.txt If either gives an error then you may have to upgrade sed to get the use of the 'inline' flag (-i) or the insert command ('i\text') to be able to do this without writing to another file first and specifying a line number. |
![]() |
| Bookmarks |
| Tags |
| non-interactive vi |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|