FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Shell scripting write/edit/delete





akoni176
How to create shell script to save then edit and delete data in a file?
jmraker
Here's a script where "ls" creates a file, "sed" edits it by replacing ".zip" with ".tmp", "grep" deletes lines that contain ".tmp". Since it's a bad idea to redirect output to a file being used in the same command, "txt1.tmp" is also used.

Code:
#!/bin/bash

ls -1 > "txt.tmp"; # Creates a file
sed -e "s/.zip/.tmp/" "txt.tmp" > "txt1.tmp"; # Edits the file
grep -v ".tmp" "txt1.tmp" > "txt.tmp"; # Deletes from the file
cat "txt.tmp";
rm "txt"*".tmp";


and here's the same thing without it creating any files
Code:
#!/bin/bash

ls -1 | sed -e "s/.zip/.tmp/"  | grep -v ".tmp"
bymenchek
thank you
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.