LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-22-2004, 05:55 AM   #1
Aylar
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Removing lines from file


Hey,

I'm working on a script where I need to remove some lines from a semi-color seperated file - example;
Animal;Cat;Black
Animal;Bird;Blue
Car;Ford Taurus;Red
Car;Ferrari 360;Yellow

Thats a silly example I know

What I want to do is remove all lines where the first field (I should mention I was hoping on using awk) matches stored in a variable, let's call it 'TYPE'.
I also want to be able to remove entries from field 2 based on a used typed regexp, so I would love to have this so flexible that it will cater for both scenarios.

Code:
#for line in $(cat $catalogue_file | awk -F";" '{print $1}' | grep -v $volume_name)
    echo $line >> after.db
done
That is the way I've envisioned it initially.. it works sort of, the problem of course is that it only writes the first field to the temp file. But I need the entire line.

I'm sure my code is a really stupid approach, so feel free to make fun :P

Thanks in avance!
 
Old 04-22-2004, 06:24 AM   #2
Aylar
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Ok, I've found a working solution for the first case, where I simply want to match against a user typed value. I haven't yet solved the regexp case.

Please comment on this, and if you got a better solution let me know!

Code:
awk -v vol="$volume_name" -F";" '$1 != vol { print $0 }' $catalogue_file >> newdb.db
 
Old 04-22-2004, 06:34 AM   #3
Aylar
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Seems like I just solved RE case too

Code:
awk -v re="$pattern" -F";" '$2 !~ re { print $0 }' $catalogue_file >>
Again, please comment if you spot any potential problems or have other solutions.
 
  


Reply


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
How can I sort the lines in a file? windhair Linux - Software 2 11-17-2005 08:37 AM
removing special lines from files Prasun1 Linux - General 3 09-11-2005 05:16 AM
[bash] removing or editing lines in file Erhnam Programming 12 03-15-2005 07:25 AM
Removing duplicate lines with sed tireseas Programming 10 01-12-2005 03:27 AM
removing lines from file script iluvatar Programming 9 08-20-2004 05:49 AM


All times are GMT -5. The time now is 11:17 AM.

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