data from input file to be taken and send to output file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
data from input file to be taken and send to output file
Hi, I am new to shell scripting.What i am trying is to write a shell script which take the input file and output should like as mentioned below.
Output file should have data till SOK (marked in red)from every second line and then the selected data(marked in green) from 4th line.
So selected data from 2nd and 4th line in one line of O/P file and then similarly selected data from 6th and 8th line in second line of O/P file.
I didn't think this was homework, and prepared a solution as a challenge. Now I have second thoughts.
Could you explain what this data represents? I'll provide a hint that I used the sed command. Also when you have a multi-line pattern, you usually need to use the hold register. Entering parts of the pattern in Google, the results were either chinese restaurants or test subject monkeys making strange sounds.
If this is a homework question, show what you have tried, and we then will will be able to provide more hints.
Last edited by jschiwal; 07-24-2010 at 11:29 AM.
Reason: second thoughts on homework issue.
Hi, I am new to shell scripting.What i am trying is to write a shell script which take the input file and output should like as mentioned below.
Output file should have data till SOK (marked in red)from every second line and then the selected data(marked in green) from 4th line.
So selected data from 2nd and 4th line in one line of O/P file and then similarly selected data from 6th and 8th line in second line of O/P file.
Output File should look like:
c1111;11.11.11.11;pOK;SOK;pERROR;SERROR
IE3333;11.11.11.11;pOK;SOK;pOK;SERROR
regards,
g
I echo the sentiments of jschiwal...show us what you've tried. We will all be glad to HELP you with this, but we're not going to write it for you. There are thousands of online shell scripting tutorials you can find via Google.
Hey Guys, this is not an homework .The input file is a result of corba script which runs on one of the applications of telecom network.
Ok, great....now again show us what you've written/done, and where you're getting stuck. Again, we're not going to write it for you, but will be glad to help you with it.
So it seems you have yet to learn about [ code ][ /code ] tags (without the spaces), but as for your code, it seems to get what you want and also a little
extra as one of your fields (number 4) has a colon and not a semi-colon. So here is something that looks ok:
#!/bin/bash
while read -r line
do
IFS=";"
set -- $line
case "$1" in
"<"*)
printf "${1/< /};$2;$3;${4%:*};"
;;
">"*)
echo "$3;${4%:*}"
esac
done <"file"
while read -r line
do
IFS=";"
set -- $line
case "$1" in
"<"*)
printf "${1/< /};$2;$3;${4%:*};"
;;
">"*)
echo "$3;${4%:*}"
esac
done <"file"
I cannot see any output.Also i want to get rid of arrow and the space marked in red from the output which i am getting from the code i wrote. Assist.
< c1111;11.11.11.11;pOK;SOK:abcde;Universe:aa
---
> cz22222;11.11.11.11;pERROR;SERROR;Universe:aa
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.