radix655
asked on
How to get the substring from a line.
soemthing ..... [SourceSystemCode<25101>=7 89] something else.
How do I get the substring using awk
I am trying to use the index function.
awk '{ substr($0, index($0, "<25101>=")+8, not sure what index I should pass here... }'
Please suggest.
How do I get the substring using awk
I am trying to use the index function.
awk '{ substr($0, index($0, "<25101>=")+8, not sure what index I should pass here... }'
Please suggest.
If you could give us sample input and output, that would be great.
ASKER
Sample Input:
[Source<25101>=sr2][Source SystemCode <25102>=sr 3]
[Source<25101>=sr3][OrderI d<25102>=s r3]
Sample Output:
sr2
sr3
[Source<25101>=sr2][Source
[Source<25101>=sr3][OrderI
Sample Output:
sr2
sr3
ASKER
Please use this.
Sample Input:
[Source<25101>=sr2][Source SystemCode <25102>=sr 3]
[Source<25101>=source3][Or derId<2510 3>=101]
Sample Output:
sr2
source3
Sample Input:
[Source<25101>=sr2][Source
[Source<25101>=source3][Or
Sample Output:
sr2
source3
Thanks radix,
Does it have to be awk, or are sed or Perl OK?
Does it have to be awk, or are sed or Perl OK?
ASKER
It has to be awk please if possible.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, why do you prefer awk?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Amazing. Thanks.
Nice work, wesley.
radix, mine could be written better as:
perl -pe 's/^.+<25101>=(.+?)].+/$1/ ' inputfile
radix, mine could be written better as:
perl -pe 's/^.+<25101>=(.+?)].+/$1/
@tel2
you might want to check radix first question, it is very challenging in shell script but easier in Perl.
https://www.experts-exchange.com/questions/27239450/Script-to-get-count-of-parent-Orders.html
you might want to check radix first question, it is very challenging in shell script but easier in Perl.
https://www.experts-exchange.com/questions/27239450/Script-to-get-count-of-parent-Orders.html
Thanks wesly,
Yes, I had seen that question, and was ignoring it because:
1. He hadn't responded to your request for more data yet.
2. I don't know if I have time.
Yes, I had seen that question, and was ignoring it because:
1. He hadn't responded to your request for more data yet.
2. I don't know if I have time.
In getting the index, what are you trying to achieve? Are you wanting to return the whole line starting from "<25101>="? If so, there are probably better ways.