![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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 |
|
||||
|
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... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|