grep -n "Table structure" database.sql sed -n '[starting_line_number],[ending_line_number] p' database.sql.sql > database_one_table.sql
Tag Archives: sed
sed add text to end of line after match
sed -i '/^search_string\=/ s/$/,text_to_add/' file
sed add new line after match
sed -i 's/search_string/&\n/g' file
bash extract domain from url
echo "https://www.srv24x7.com/" | sed -e 's|^[^/]*//||' -e 's|/.*$||'
linux remove ^m characters
sed -e "s/\r//g" file > newfile
remove lines with string
sed -i '/string/d' somesime.txt
sed add to the beginning of line
sed -i 's/^/*@/' somefile.txt
sed replace recursive
grep -rl oldtext . | xargs sed -i 's/oldtext/newtext/g'
sed remove emty lines, trim
sed 's/^ *//; s/ *$//; /^$/d; /^\s*$/d' file.txt > output.txt
`s/^ *//` => left trim
`s/ *$//` => right trim
`/^$/d` => remove empty line
`/^\s*$/d` => delete lines which may contain white space
sed remove blank space beginning of line
echo " This is a test" | sed -e 's/^[ \t]*//'
If not works, maybe you file have some special not visable charters, like BOM or M-oM-?M-
you can reove them to output to some temporary file and use sed or vi editor to remove them.
sed remove empty line
sed '/^\s*$/d'
linux comment line which start with some string
sed s/^character-set-server=utf8/#character-set-server=utf8/’ -i /etc/my.cnf
If you want comment on this this line “character-set-server=utf8” on all your servers, you should use something like ansible:
ansible mysql_servers -m shell -a “sed -e ‘s/^character-set-server=utf8/#character-set-server=utf8/’ -i /etc/my.cnf”
bash remove last line from log file
sed -ie ‘$d’ some_file.log