LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Text substitution and processing with sed and awk (https://www.linuxquestions.org/questions/linux-newbie-8/text-substitution-and-processing-with-sed-and-awk-691370/)

shanecraddock@gmail.com 12-17-2008 10:37 PM

Text substitution and processing with sed and awk
 
Hey guys, I'm fairly new to this but I am looking for a way to replace text in one file based on pattern matching.

file1.txt is the result of ls -l --color=no /usr/local/mysql/data | awk '{print $4,$9}' | sort | cut -d/ -f1 > file1.txt

(note: this generates a list of about 1000 lines)

So it contains on the left a group name and on the right a database name, e.g.
vvsoccer thunder

I have another file, file2.txt, that contains all domain names on the system eg
(note: file2.txt has about 2000 domains/lines)

vvsoccersummer.com
and 1999 others, one per line.

I need to find a way to create a file3.txt that contains the domain name (from file2) and the database name.

I've tried comm -3 file1.txt file2.txt | sort but with no luck... file2.txt also contains domain names that don't necessarily have any databases in /usr/local/mysql/data

Any help or ideas would be great, i've been racking my brain for 5 hours now...

Thanks in advance for any and all input.

-Shane

openSauce 12-18-2008 11:34 AM

How do you know which domain name goes with which database name? Is vvsoccer thunder supposed to go with vvsoccersummer.com, and if so why?

The answer to that question will determine what you need to do to merge the files together.

PS shouldn't your awk command be printing $8 instead of $9? Unless you have some weird version of ls, but when I do ls -l there are 8 fields per line (unless there are spaces in the filenames of course, something else you need to watch out for)


All times are GMT -5. The time now is 07:26 PM.