ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ive been bashing my head on this one trying to look at different AWK scripts to split my file into smaller files based on a specific line.
At the top of every file theres a line that reads:
Code:
/ info / info / servername / info / info / info / info
then a bunch of data under it reading:
Code:
Wed Feb 01 08:51:24 EST 2012,Wed Feb 01 08:51:44 EST 2012,1098.35,
Wed Feb 01 08:51:44 EST 2012,Wed Feb 01 08:52:04 EST 2012,915.25,
Wed Feb 01 08:52:04 EST 2012,Wed Feb 01 08:52:24 EST 2012,937.7,
Wed Feb 01 08:52:24 EST 2012,Wed Feb 01 08:52:44 EST 2012,957.25,
Wed Feb 01 08:52:44 EST 2012,Wed Feb 01 08:53:04 EST 2012,703.3,
Wed Feb 01 08:53:04 EST 2012,Wed Feb 01 08:53:24 EST 2012,757.75,
Wed Feb 01 08:53:24 EST 2012,Wed Feb 01 08:53:44 EST 2012,891.8,
Wed Feb 01 08:53:44 EST 2012,Wed Feb 01 08:54:04 EST 2012,951.75,
Wed Feb 01 08:54:04 EST 2012,Wed Feb 01 08:54:24 EST 2012,997.25,
Wed Feb 01 08:54:24 EST 2012,Wed Feb 01 08:54:44 EST 2012,1018.4,
Wed Feb 01 08:54:44 EST 2012,Wed Feb 01 08:55:04 EST 2012,1046.95,
Wed Feb 01 08:55:04 EST 2012,Wed Feb 01 08:55:24 EST 2012,838.3,
Wed Feb 01 08:55:24 EST 2012,Wed Feb 01 08:56:04 EST 2012,912.05,
What i need to do is read that first line then take every line and out put it to another file named the servername. There are multiple servers in the same file that start with that first line:
Code:
/ info / info / servername / info / info / info / info
no validity checking whatsoever, but if your input is reliable, should be fine. Offhand, I'm not totally sure if the server name will be the 3rd or 4th field, as the line starts with a field seperator. I'd expect it to be the 4th though.
Last edited by acid_kewpie; 03-21-2012 at 10:43 AM.
no validity checking whatsoever, but if your input is reliable, should be fine. Offhand, I'm not totally sure if the server name will be the 3rd or 4th field, as the line starts with a field seperator. I'd expect it to be the 4th though.
I tried to execute the code but was getting syntax erors...
Using spaces in the field separator avoids spaces in the output file name. Then basically you have to explicitly redirect the output of the print statement to the output file, using the ">" symbol as in bash (the only difference with bash redirection is that the output is appended by default).
I'm assuming that Toronto MDS_GW2 is not unique, so I used /\// which looks for a forward slash (which needs to be escaped, it has special meaning in awk). I also believe $3 should be $4.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.