The UNIX and Linux Forums  

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
Need to insert new text and change existing text in a file using SED iamgeethuj Shell Programming and Scripting 4 11-25-2008 03:59 AM
How to insert some constant text at beginig of each line within a text file. Muhammad Afzal Shell Programming and Scripting 4 10-30-2008 11:01 PM
insert some text to a file log bucci Shell Programming and Scripting 4 05-09-2007 08:19 AM
insert text into top of file jimbob Shell Programming and Scripting 1 09-22-2006 06:46 PM
SED- Insert text at top of file MBGPS Shell Programming and Scripting 12 07-03-2002 10:48 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2009
harshakusam harshakusam is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 11
Insert Text On file

Hi All,

Can someone pls help me to insert some text on a file.

my file contains something like below..

AKBULBU,
BALUMIL,
BATCH,BATCH
BOARROB,
BOTAKAT,
C57896,
CAKIOZE,
CHECMER,
CICOFRA,
CISZPAW,2194485

I want output as

USER_ID, LOGIN_ID
AKBULBU,
BALUMIL,
BATCH,BATCH
BOARROB,
BOTAKAT,
C57896,
CAKIOZE,
CHECMER,
CICOFRA,
CISZPAW,2194485
  #2 (permalink)  
Old 08-20-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813

Code:
echo "USER_ID, LOGIN_ID" > tmp; 
cat file >> tmp; 
## at this point check the content of tmp before you do this, mv will erase the 
mv tmp file

  #3 (permalink)  
Old 08-20-2009
Shazin Shazin is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gurgaon, India
Posts: 77
Hia,

You can also use:

Code:
sed '1i\ USER_ID, LOGIN_ID' file_name > new_filename
cp new_filename file_name
rm new_filename

Cheers,
Shazin
  #4 (permalink)  
Old 08-20-2009
harshakusam harshakusam is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 11
Hi jim,

Can same be done by using SED
  #5 (permalink)  
Old 08-20-2009
harshakusam harshakusam is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 11
hi shazin,

When iam doing this iamgetting error


Code:
$ sed '1i\ USER_ID, LOGIN_ID' userdata.csv >newfile
sed: command garbled: 1i\ USER_ID, LOGIN_ID


Last edited by Franklin52; 08-20-2009 at 01:27 PM.. Reason: code tags
  #6 (permalink)  
Old 08-20-2009
Shazin Shazin is offline
Registered User
  
 

Join Date: Jul 2009
Location: Gurgaon, India
Posts: 77
Hi ,

Please can you make use of CODE options on the control bar to keep the Forum tidy.

Thanks,
Shazin
  #7 (permalink)  
Old 08-20-2009
harshakusam harshakusam is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 11
hi shazin,

When iam doing this iamgetting error



Code:
$ sed '1i\ USER_ID, LOGIN_ID' userdata.csv >newfile
sed: command garbled: 1i\ USER_ID, LOGIN_ID

Reply

Bookmarks

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 07:52 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