The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
How to insert text into first line of the file and middle of the file? ali hussain Shell Programming and Scripting 3 03-05-2007 05:54 AM
insert file 1 at a specific place of file 2 JCR Shell Programming and Scripting 1 02-01-2007 11:48 AM
extract content from a file and insert to another file fredao Shell Programming and Scripting 15 12-06-2006 07:36 PM
Insert date/time within a filename cooperman UNIX for Dummies Questions & Answers 7 11-07-2005 12:29 PM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 09:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-06-2006
USER#5 USER#5 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 1
insert filename into file using SED (or AWK)

Hi,
I would like to insert a file's filename into the first line of that file - for a batch of files. Is this possible using SED? Thanks in advance.
  #2 (permalink)  
Old 08-06-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
for file in `ls -1 *`
do
    echo "$file" > ./tmpfile
    cat "$file" >> ./tmpfile
    mv ./tmpfile "$file"
done
is one way to do this.
  #3 (permalink)  
Old 08-06-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
How about this:
Code:
for i in *; do
ex $i <<EOF
i
$i
.
wq
EOF
done
I doubt that it would be very easy to do it using sed, as sed writes to standard output. You would have to pull stunts like redirecting standard output to a file at the beginning of the script and changing that for every file that you want to change...
Closed Thread

Bookmarks

« Sos | timeup »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0