The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
write new line at the beginning of an existing file sailussr UNIX for Dummies Questions & Answers 5 11-06-2008 05:42 PM
Need Help for Adding Three new columns in existing file from fatching data from file Sandeep_Malik Shell Programming and Scripting 36 09-17-2008 06:12 PM
Need to add a line of data to already existing file in Unix.. charan81 Shell Programming and Scripting 4 01-21-2006 03:31 AM
Print one line of Existing File danhodges99 UNIX for Dummies Questions & Answers 2 02-25-2003 11:56 AM
help on appending data to existing data precious51980 UNIX for Dummies Questions & Answers 1 01-27-2001 12:56 PM

Closed Thread
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 02-06-2009
fletcher fletcher is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
Add line with data to existing file

i have a file called motors with 3 columns separated with tabs eg:
car make reg
i want to create a executable file that will add a line with data eg:
car make reg
benz s600 t35778
can you please show me how to do this?
  #2 (permalink)  
Old 02-06-2009
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
You can easily append data to the end of a file

Code:
echo "benz s600 t35778" >> motors

What do you have thus far?
  #3 (permalink)  
Old 02-06-2009
fletcher fletcher is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
adding tabs

thanks that works fine...
but do you know how to add tabs on the appended line so that it matches the top column?
  #4 (permalink)  
Old 02-06-2009
fletcher fletcher is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
append using awk

can i apend the file using awk so i can use variables, if so please can you show me how?
  #5 (permalink)  
Old 02-07-2009
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Please describe where the data will be coming from and how it is currently formatted (with examples).
Will you be running this script repeatedly, or is it a one time deal?
  #6 (permalink)  
Old 02-08-2009
fletcher fletcher is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
where data come from

the data will come from the user, the user will input the data from the bash.
there is an existing file called appointments with colummn 3 headings saperated by tabs date time venue

what i want is the user to append data to that file by typing an executable file first called addfile followed by parameters 24/12/78 14.04 newyork eg.
$ addfile 14/12/78 14.04 newyork

to produce a file like this:
date time venue
14/12/78 14.04 newyork

thanks
  #7 (permalink)  
Old 02-09-2009
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Here's the code in sh (bourne)

Code:
#!/usr/bin/sh

FILE="/path_to_file/appointments"

COL1=$1
COL2=$2
COL3=$3

if [ -f $FILE ]
then
   echo "$COL1\t$COL2\t$COL3\t" >> $FILE
else
   echo "File \"$FILE\" not found "
   exit 0
fi
exit 0

You'll probably want to:
1. add some error handling for when users don't provide three variables.
2. if you change this script to bash, you'll need to replace \t
3. add some usage message for the users.

It could be simplified to replace "$COL1" with $1, $COL2 with $2, $COL3 with $3 - but you probably want to know what is going on...
Closed Thread

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 01:03 PM.


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