Latest Entries »

Basic Format

grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

Example

grep -rl 'windows' ./ | xargs sed -i 's/windows/linux/g'

Advertisements
<html>
<head>
<script type="text/javascript">

var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "firstcar.gif" // set image object src property to an image's src, preloading that image in the process
slideimages[1] = new Image()
slideimages[1].src = "secondcar.gif"
slideimages[2] = new Image()
slideimages[2].src = "thirdcar.gif"

</script>
 </head>
<body>
<a href="javascript:slidelink()"><img src="firstcar.gif" id="slide" width=100 height=56 /></a>

<script type="text/javascript">

//variable that will increment through the images
var step = 0
var whichimage = 0

function slideit(){
 //if browser does not support the image object, exit.
 if (!document.images)
  return
 document.getElementById('slide').src = slideimages[step].src
 whichimage = step
 if (step<2)
  step++
 else
  step=0
 //call function "slideit()" every 2.5 seconds
 setTimeout("slideit()",2500)
}

function slidelink(){
 if (whichimage == 0)
  window.location = "link1.htm"
 else if (whichimage == 1)
  window.location = "link2.htm"
 else if (whichimage == 2)
  window.location = "link3.htm"
}

slideit()

</script>
</body>
</html>

source: http://www.javascriptkit.com/howto/show3.shtml

Backuping a single table from a database

pg_dump -U username -d database1 -t table_name > /home/backups/table_name.sql

Restoring the table into another database

psql -U username -d database2 < /home/backups/table_name.sql

test_db=# select address from test_table;

58/171-G, RAJAPURAM,\r                                                                                                                                                                                                                                                                                                                                                                                                              +
PALANIAPPA NAGAR,\r                                                                                                                                                                                                                                                                                                                                                                                                                 +
SALEM
TS.No.5823,SANTHANATHAPURAM FOURTH STREET\r                                                                                                                                                                                                                                                                                                                                                                                         +

 

solution
test_db=# update test_table set address= regexp_replace(address, E'[\\n\\r]+’, ‘ ‘, ‘g’);

test_db=# select address from test_table;

58/171-G, RAJAPURAM,

PALANIAPPA NAGAR,

SALEM TS.No.5823,SANTHANATHAPURAM FOURTH STREET

Grant Privileges Postgres

Database:

GRANT ALL PRIVILEGES ON DATABASE DATABASENAME to USER;

Table:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO USER;

Id Seq Tables:

GRANT ALL PRIVILEGES  ON ALL SEQUENCES IN SCHEMA public TO USER;

To find number of files in a directory use the following command:

ls | wc -l

To find number for rows in a csv file use the following command:

wc -l filename.csv

grep command syntax

The syntax is:

grep "text string to search” directory-path

OR

grep [option] "text string to search” directory-path

OR

grep -r "text string to search” directory-path

OR

grep -r -H "text string to search” directory-path

OR

egrep -R "word-1|word-2” directory-path

OR

egrep -w -R "word-1|word-2” directory-path

postgres=#SELECT datname, (pg_stat_file(‘base/’||oid||’/PG_VERSION’)).modification AS datcreated
FROM pg_database;

datname | datcreated
——————-+—————————
template1 | 2014-05-06 15:44:37+05:30
template0 | 2014-05-06 15:44:38+05:30
postgres | 2014-05-06 15:44:38+05:30
abc | 2014-07-01 12:58:31+05:30
xyz | 2014-07-03 11:01:38+05:30

Nano

Find  :  ctrl + W

Find and Replace :

Ctrl \
Enter your search term [press return]
Enter your replacement term [press return]
A [to replace all instances]

Select: ALT + M + A
Copy: ALT + 6 (copy as many lines as you like, and they will be pasted in the order you copied them)
Paste: CTRL + U