skip first line in mysql export to .txt file in linux -
i want create sitemap google. fastest way (i think) exporting query straight txt file linux command. this
$ mysql -pmypassword -e "select concat('http:/mysitecom/',id,'/',urlpart1,'/',urlpart2,'/') url products limit 50000" > /home/file.xml the problem google says there has nil urls in txt file, , first line "url" resulting column name, typical csv file. how can skip it?
piping tail should work
mysql -pmypassword -e "select concat('http:/mysitecom/',id,'/',urlpart1,'/',urlpart2,'/') url products limit 50000" | tail -n +2 > /home/file.xml do remember you'll have each time table updated. depending on implementation of site i'd imagine wouldn't complex write query , output list @ endpoint such domain.com/sitemap - language using?
pretty simple:
// regular database connection $db = mysqli_connect(...); $resource = mysqli_query($db, "select concat('http:/mysitecom/',id,'/',urlpart1,'/',urlpart2,'/') url products"); while ($arr=mysqli_fetch_row($resource)){ $urls[]=$arr[0]; } header('content-type: text/plain'); foreach ($urls $url){ echo $url.php_eol; } should work haven't tested it! (esp. header, that's off top of head)
mysql linux
No comments:
Post a Comment