Results 1 to 4 of 4
I have this file and i need a command to permanently add a line of code to the file and sort the file by ID. I was able to add ...
- 06-10-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 4
Adding lines to file
I have this file and i need a command to permanently add a line of code to the file and sort the file by ID. I was able to add a line with the echo command but its not permanent. Any help is appreciated.
Code:111:Smith:Mary:Davison:Attorney 222:Stumblebum:Jason:Novi:Student 229:Esposito:Amy:Toronto:Artist 444:Adams:Mary:San Francisco:Psychiatrist 555:Roberts:Tim:Fenton:Student 666:Koresh:Ken:Fenton:Student 777:Gibson:Andrew:Linden:Merchandiser
- 06-10-2011 #2Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,940
What programming language are you using?
The echo command prints to screen and doesn't by itself write to any file. ]
Actually, it would be best if you indicated what programming language and whether this is something you will need a script for, you will be doing it on a regular basis?
- 06-11-2011 #3Just Joined!
- Join Date
- Nov 2006
- Location
- near Berea, Kentucky (in a tipi)
- Posts
- 34
I am gonna take a stab at it...
I'm assuming you are scripting in bash (or some shell), and that you only and always want to append a final line to the file.
On command line or in bash (or other shell) script
echo "Line of text" >>filename
appends Line of text to file named filename, permanently.
In scripts, text line and filename may be/probably are variables, so you need to properly escape them (may contain special characters). Any good scripting tutorial should describe this.
Does that help?
- 06-11-2011 #4Just Joined!
- Join Date
- Dec 2009
- Location
- California
- Posts
- 69
I don't mean to point out the obvious, but this clearly appears to be a class question.
The other poster already mentioned echo and redirection, so you should be fine there.. As for the sorting, I would use "man sort". Specifically, you need probably need to use the -n option (unless you can be 100% sure that the numeric id's are all exactly 3 characters long). Try adding an entry with an id of 99 and watch what happens.
Also, you'll need to sort by field....


Reply With Quote