Skip to content
Advertisement

need help on shell script for expected output

I have an input file called input.txt like this:

JavaScript

I extract the text up to just before the fist capital letter in the first field and store those snippets in output.txt:

JavaScript

I used the sed command to separate out the values and it’s working fine.

From the output file (output.txt), I need to grep from the first field, and output should be like below:

JavaScript

I have tried a few ways but I’m not getting the expected output.

I tried the following but I’m getting duplicate entries:

JavaScript

I have 20000 lines in the input file. I don’t know why I am getting duplicates the output. What am I doing wrong?

Advertisement

Answer

Bash solution:

JavaScript

Maybe a Perl solution is acceptable for OP too:

JavaScript

Test with your given input:

JavaScript

UPDATE after OP has re-stated the original problem. Solution for the first loop that only includes the 2nd column of the input instead of the whole line:

JavaScript

Test with your given input:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement