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. Input File: 3c3 < c1111;11.11.11.11;pOK;SOK:abcde;Universe:aa --- > cz22222;11.11.11.11;pERROR;SERROR;Universe:aa 44c44 < IE3333;11.11.11.11;pOK;SOK:bbbbb;Universe:bb --- > IE4444;11.11.11.11;pOK;SERROR;Universe:dd 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 |
Is this homework? If so, you should be doing it on your own....
|
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. |
Quote:
And this does sound like homework..... |
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.
|
Quote:
|
haha, i just saw the last post. Tomorrow i will spare some 15-20 min and i will finish this off. I will post you then :)
|
Here comes the much awaited script you all were looking for :).
rm rout i=1 sed -n 'n;p' $1 | while read line do if [[ $i -eq 1 ]] then L1=`echo $line | cut -d';' -f1,2,3,4` i=0 continue else L2=`echo $line | cut -d';' -f3,4` i=1 fi echo $L1";"$L2 >> rout done |
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: Code:
awk 'BEGIN{FS="[:;]";OFS=";"}/^[<>]/{if(!a){a = gensub($5".*","","g")}else{print a,$3,$4;a=""}}' file |
Code:
#!/bin/bash |
Hey,thanks but when i tried with
awk 'BEGIN{FS="[:;]";OFS=";"}/^[<>]/{if(!a){a = gensub($5".*","","g")}else{print a,$3,$4;a=""}}' file I am getting awk: syntax error near line 1 awk: illegal statement near line 1 Please advise. |
Hey, with this code...
--------- #!/bin/bash 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 |
You are using your data stored in the file name 'file'?
I used it on the data you provided and received the following output: Code:
< c1111;11.11.11.11;pOK;SOK:;pERROR;SERROR |
does that work?
|
Off topic
A little of topic
Quote:
[code] [/code] Somebody pointed this out to me about a year ago or so :) |
All times are GMT -5. The time now is 02:28 AM. |