New Line help needed

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New Line help needed
# 1  
Old 10-11-2009
New Line help needed

I am doing a simple SHOW DATABASES query:

echo `mysql -e "SHOW DATABASES;"`

It produces this:

Database information_schema mysql test

There are 2 things I want to do, but failing at.
1. Exclude the header "Database information_schema"
2. add a new line between each database "\n"

I'm running into walls for both of them.

I've tried different ways to use tail +2 (echo `mysql -e "SHOW DATABASES;"` | tail +2) - but to no avail. And the new line is elusive.

Any thoughts?
# 2  
Old 10-11-2009

Why are you using echo at all?

That will only help to supress the newlines.

If you have to perhaps use the -e option

man echo

(-e is only available on Linux!)
# 3  
Old 10-11-2009
What's the output from 'mysql -e "SHOW DATABASES;"' on it's own look like?
Without seeing the raw output we're working with it's hard to be sure, but I would guess you want something like:
for database in `mysql -e "SHOW DATABASES;" | tail +2`
  echo $database

# 4  
Old 10-18-2009

for dbName in `mysqlshow -uroot -pPassWord | awk '{print $2}'`
echo "$dbName" | egrep -v 'mysql|test|Databases|information_schema';

# 5  
Old 10-19-2009
db=$( mysql -e "SHOW DATABASES;" )
printf "%s\n" "$db"

# 6  
Old 10-19-2009
Assuming the output is like this:
| Database           |
| information_schema |
| mysql              |
| test               |

mysql -e "SHOW DATABASES;"|grep -o '\w*'|tail -n +3

will produce:

# 7  
Old 10-19-2009
Originally Posted by scottn
If you have to perhaps use the -e option

man echo

(-e is only available on Linux!)

Not so. It is part of bash, which may be found on any system.

However, echo is deprecated; use printf instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

2. Shell Programming and Scripting

Help needed in reading line value into variable

I have a file which has data in 8 lines: 10 34 6 1 4 46 67 31 I am trying to read each value into each different variable so that I use these variables in preparing my report. Another option is to dynamically print each line values in the report like below: users with privA:... (2 Replies)
Discussion started by: sarat949
2 Replies

3. Shell Programming and Scripting

Needed a help in inserting a new line!!!

Hi..wanted a help regarding inserting a newline in an xml file using shell script. i've an xml file which has the following data. 1. <?xml version="1.0" encoding="UTF-8"?> 2. <group> 3. <name>odcm</name> 4. contd.... I need to insert two new lines after line#2, so that the output... (14 Replies)
Discussion started by: arjun_arippa
14 Replies

4. Shell Programming and Scripting

Help needed for diff to ignore a line with certain pattern

Hello Guys, I request anyone to do me a small help in using diff command for following. I am trying to compare two files for content and wish to keep the content after the comparison (The resultant file can't be blank) However, the first lines would be different in both files and I need diff... (2 Replies)
Discussion started by: rockf1bull
2 Replies

5. Shell Programming and Scripting

Help needed to split a line

Hi, How can i split a line of string into two lines. I would like to format the below string: Filesystem 1M-blocks Used Available Use% Mounted on /abc/def/xyz 34567 2345 12345 90% /test to Filesystem 1M-blocks Used Available Use% Mounted on /abc/def/xyz 34567 2345 12345 90% /test ... (4 Replies)
Discussion started by: stunnerz_84
4 Replies

6. Shell Programming and Scripting

help needed with shell script to append to the end of a specific line in a file on multiple servers

Hi Folks, I was given a task to append three IP's at the end of a specific (and unique) line within a file on multiple servers. I was not able to do that with the help of a script. All I could was: for i in server1 server2 server3 server4 do ssh $i done I know 'sed' could be used to... (5 Replies)
Discussion started by: momin
5 Replies

7. Ubuntu

Command line email help needed

Hi, having some problems getting commandline mail to work for root user in ubuntu. Ive installed the following packages - msmtp & mailx and the cert for gmail. I've created 3 files: mailrc and msmtprc in /home/username directory and /etc/exim4/passwd.client mailrc ------ set... (0 Replies)
Discussion started by: ziggycat
0 Replies

8. Shell Programming and Scripting

sed/shell scripting - add line if needed and not allready there

I am writing a shell script that checks all .c files to see if they use fprintf or printf. If a file does, then the line #include <stdio.h> is added to the top of the file, unless it's already there. This is what I've got: #!/bin/sh egrep -l f?printf *.c | while read file; do sed -i '1i\... (2 Replies)
Discussion started by: computethis
2 Replies

9. Shell Programming and Scripting

Line Replacement help needed.

I have a file called vm.cfg which looks like follows # cat vm.cfg acpi = 1 apic = 1 builder = 'hvm' device_model = '/usr/lib/xen/bin/qemu-dm' disk = kernel = '/usr/lib/xen/boot/hvmloader' memory = '300' name = 'vm_temp' on_crash = 'restart' on_reboot = 'restart' pae = 1 serial =... (5 Replies)
Discussion started by: pinga123
5 Replies

10. UNIX for Advanced & Expert Users

search a replace each line- help needed ASAP

can someone help me with the find and replace command. I have a input file which is in the below format: 0011200ALN00000000009EGYPT 000000000000199900000 0011200ALN00000000009EGYPT 000000000000199900000 0011200ALN00000000008EGYPT 000000000000199800000 0011200ALN00000000009EGYPT ... (20 Replies)
Discussion started by: bsandeep_80
20 Replies
Login or Register to Ask a Question