Parse through two files and concatenate strings into one file using bash
bash, concatenation, grep
Solution
Answer for revised question
$ paste -d '' foo.txt foo2.txt | grep -v '^\*'
2B
4D
Answer for original question
$ paste -d '' foo.txt foo2.txt | grep '^\*'
*1A
*3C
*5E
How it works
`paste -d '' foo.txt foo2.txt`
This combines the two files line by line. The option `-d ''` tells paste to combine the lines directly with no intervening whitespace.
`grep '^\*'`
This selects only those lines which begin with `*`.
For the revised question, we add `-v` which inverts the match: `grep -v '^\*'` removes the lines that start with `*`.
Problem
I have two text files which I would like to parse through, then combine the two lines parsed into one file using a `grep` call. For example: ``` Foo.txt Foo2.txt *1 A 2 B *3 C 4 D *5 E ``` I would like to have ``` FooFinal.txt 2B 4D ``` I am attempting to use the grep command as so ``` grep -A 1 '*' Foo.txt|grep -v '*' ``` but, I am not sure how to grep both files. I would assume one would use a `paste` command to concatenate, but I am not sure. Also, if this is difficult to understand, please let me know so I can clarify. Thanks!