How to Separate this using Awk!!
Hi all,
I am Writing a Script, in that i struggling in this part alone, This is two Rows of a file. Quote:
and my requirement is like this. Quote:
|
If you are using awk, you could use the built-in variables FS and OFS.
See http://www.thegeekstuff.com/2010/01/...-filename-fnr/ It does seem like you need to trigger some re-evaluation if you just want to do a 'print $0': Code:
janhe@hostname:~$ echo -e "1,2,3\n4,5,6" | awk 'BEGIN{FS=","; OFS=";";} {$1=$1; print $0}' Code:
janhe@hostname:~$ echo -e "1,2,3\n4,5,6" | tr "," ";" |
Hi
Thanks for the Reply man. This is for one line in a file, but n number of rows in a file like this then how i used this command man. |
I demonstrated it with two lines.
It will work the same way with any number of lines. |
Am I missing something, or is removing the commas the only thing you really need to do?
Code:
sed 's/,//g' file Code:
sed 's/, /\t/g' file |
Or the awk equivalent:
Code:
awk -F, '$1=$1' OFS="\t" file |
Hi all,
Thanks alot guys, for your immediate response and sorry for the late reply. Actually using your command i remove the comma and get the output what i expect. but still the script working is going, My requirement is like this. Code:
anis.com smallbusiness db_docupoint db_urlforwarding db_asgroupdemo online and my requirement is every time the script runs it creates on directory in the client name(column1) and start dumping the databases(column 2,3,4,5,6) using mysql dump, and move those dump databaes into (column1) directory. like this we have to do for our every clients. is it possible to do ? guide me guys to solve this thread. |
So how about we start at the beginning and you tell us exactly what is required instead of spoon feeding us bits and pieces?
My first question to you would be, what is the manual process you currently use to do whatever it is you are trying to accomplish? (ie if you type one command at a time on the command line how can you accomplish your task) |
I can see that English isn't your first language. There's nothing you can do about it, as long as you are trying your best. I does make it hard for me to understand what you want exactly.
I understand that you want to execute some external programs. You can do that inside awk: Code:
BEGIN { You can adapt my example for the purpose you really need. |
Hi grail,
Thanks Man, Even Iam also not like Spoon feeding, and my exact requirement is am writing a script to take mysql backups in shared hosting, using plesk control panel we configured shared hosting in our server, Code:
#!/bin/bash but my requirement is need to take all the databases backup with owner details ( owner details in the sense need to create directory in the name of client name.) so first i follow these steps to customize the above script. 1. need to get the client name and databases name. so using the mysql query i get the client name and along with the corresponding databases. if i execute a mysql query means i got this output. Quote:
Sorry my English is very poor i know..i hope will improve.. kindly read the above all the posts i hope you understand my requirement |
No problems on not having great English as those that supposedly can speak it are often not very eloquent anyway :)
I think I am following better now, but just want to know at what point in the script you have shown would you now run the mysql query to retrieve the data in the format you mention? I only ask as the script appears to already be making backups. Is this new requirement to happen after all of what we currently see? |
Hi grail,
Thanks for the patience To Read my English :-) ya dude this is my new requirement, i need to add this in script. but still i didn't get any idea for this requirement struggling, Code:
mysql -u admin -pPASSWD -D psa -Bse "select a.name, group_concat(b.name separator ', ') from domains a, data_bases b where a.id=b.dom_id group by a.name;" Quote:
Example: Code:
ls anis.com/ |
Well I would say the easiest thing to do would be simply change the separator to a space (not sure if that is the default as not familiar with mysql).
So I would probably do some thing like: Code:
while read -r client dbs |
Hi grail,
Thanks For the Reply. Sorry for the late reply we are in celebration mood (Independence day here :-)) but still My Script Problem is continuing :-( :-( Code:
bbkup.sh: line 9: syntax error near unexpected token `<' |
Why is there a semi-colon at the end of the second errored line?
Why are there 2 scripts? What is at line 9 in the first script? |
All times are GMT -5. The time now is 04:27 AM. |