Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-17-2008, 10:37 PM   #1
LQ Newbie
Registered: Dec 2008
Posts: 10

Rep: Reputation: 0
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)
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.

Old 12-18-2008, 11:34 AM   #2
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
How do you know which domain name goes with which database name? Is vvsoccer thunder supposed to go with, 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)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Manipulating Text File with awk or sed kushalkoolwal Programming 2 09-10-2008 07:35 PM
Modify a text files with awk/sed/perl climber75 Programming 15 08-05-2008 03:35 PM
parsing text using sed/awk or similar??? freeindy Programming 5 07-24-2008 04:04 AM
awk/sed to grep the text ahpin Linux - Software 3 10-17-2007 12:34 AM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration